Uh oh!
There was an error while loading. Please reload this page.
Add TypeScript Mapped Draft Type - #161
Merged
Merged
Conversation
knpwrs
commented
Jun 9, 2018
ContributorAuthor
I just pushed a commit to make the interfaceState{readonlyfoo: number;readonlybaz: {readonlyx: number;readonlyy: number;};}I'm still trying to figure out how to make arrays work properly. |
knpwrs
commented
Jun 9, 2018
ContributorAuthor
Looks like everything is working now. All of the following compiles and works as expected: importproducefrom'immer';interfaceState{readonlynum: number;readonlyfoo?: string;bar: string;readonlybaz: {readonlyx: number;readonlyy: number;};readonlyarr: ReadonlyArray<{readonlyvalue: string}>;readonlyarr2: {readonlyvalue: string}[];}conststate: State={num: 0,bar: 'foo',baz: {x: 1,y: 2,},arr: [{value: 'asdf'}],arr2: [{value: 'asdf'}],}constnewState=produce<State>(draft=>{draft.num++;draft.foo='bar';draft.bar='foo';draft.baz.x++;draft.baz.y++;draft.arr[0].value='foo';draft.arr.push({value: 'asf'});draft.arr2[0].value='foo';draft.arr2.push({value: 'asf'});})(state); |
ghost
commented
Jun 22, 2018
This would be really useful to us, thank you very much @knpwrs |
knpwrs
commented
Jun 23, 2018
ContributorAuthor
@mweststrate is there any interest from the project owners to add these typings? |
mweststrate
commented
Jun 23, 2018
via email
Collaborator
Yes; but didn't get to reviewing yet 😊
Op za 23 jun. 2018 19:42 schreef Ken Powers <notifications@github.com>: …@mweststrate <https://github.com/mweststrate> is there any interest from
the project owners to add these typings?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#161 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhFRsW1xcoEuuMj_GEeYBBdiVUNHAks5t_n4igaJpZM4UhG-U>
.
|
ghost
commented
Jul 20, 2018
Hello @mweststrate |
mweststrate
commented
Jul 21, 2018
Collaborator
Reviewed! No comments, looks awesome :). Will release next week |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
These changes enable the following:
This helps TypeScript users ensure immutability of their state interfaces. I had to upgrade TypeScript for the
index.d.tsfile to parse properly. This feature was merged into TypeScript back in February: microsoft/TypeScript#21919It also appears that theflow/ts.tsfile doesn't run and never did. I tested this externally and it works, but I'd like to see a more robust test suite in this repo.EDIT: I've added some TypeScript tests in Jest.
EDIT:Fixes#97