Add TypeScript Mapped Draft Type#161
Merged
mweststrate merged 9 commits intoimmerjs:masterfrom Jul 21, 2018
Merged
Conversation
Contributor
Author
|
I just pushed a commit to make the interface State {
readonly foo: number;
readonly baz: {
readonly x: number;
readonly y: number;
};
}I'm still trying to figure out how to make arrays work properly. |
Contributor
Author
|
Looks like everything is working now. All of the following compiles and works as expected: import produce from 'immer';
interface State {
readonly num: number;
readonly foo?: string;
bar: string;
readonly baz: {
readonly x: number;
readonly y: number;
};
readonly arr: ReadonlyArray<{ readonly value: string }>;
readonly arr2: { readonly value: string }[];
}
const state: State = {
num: 0,
bar: 'foo',
baz: {
x: 1,
y: 2,
},
arr: [{ value: 'asdf' }],
arr2: [{ value: 'asdf' }],
}
const newState = 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); |
|
This would be really useful to us, thank you very much @knpwrs |
Contributor
Author
|
@mweststrate is there any interest from the project owners to add these typings? |
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>
.
|
|
Hello @mweststrate |
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 free
to 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