Library of stage-0 JavaScript decorators (aka ES2016/ES7 decorators but not accurate) inspired by languages that come with built-ins like @override, @deprecate, @autobind, @mixin and more. Popular with React/Angular, but is framework agnostic.
MIT License
4.52k
stars
263
forks
source link
Issue with Redux passing {type, foo} as Action parameter #139
When using {type, foo} for the action. I am getting error below e.g. string literal BAR. Expected string literal FOO, got BAR instead HOWEVER if I use "action: Action" instead of {type, foo} is works.
type State = {};
type FooAction = { type: "FOO", foo: string };
type BarAction = { type: "BAR", foo: boolean };
type Action = FooAction | BarAction;
function reducer(state: State, {type, foo}: Action): any {
switch (type) {
case "FOO": return { ...state, foo };
case "BAR": return { ...state, foo };
default:
return state;
}
}
// Errors
9: function reducer(state: State, {type, foo}: Action): any {
^ string literal BAR. Expected string literal FOO, got BAR instead
9: function reducer(state: State, {type, foo}: Action): any {
^ string literal FOO
9: function reducer(state: State, {type, foo}: Action): any {
^ string literal FOO. Expected string literal BAR, got FOO instead
9: function reducer(state: State, {type, foo}: Action): any {
^ string literal BAR
9: function reducer(state: State, {type, foo}: Action): any {
^ boolean. This type is incompatible with
9: function reducer(state: State, {type, foo}: Action): any {
^ string
9: function reducer(state: State, {type, foo}: Action): any {
^ string. This type is incompatible with
9: function reducer(state: State, {type, foo}: Action): any {
^ boolean
11: case "FOO": return { ...state, foo };
^ string literal FOO. This === check always fails because FOO is not the same string as BAR
9: function reducer(state: State, {type, foo}: Action): any {
^ string literal BAR
When using {type, foo} for the action. I am getting error below e.g. string literal
BAR
. Expected string literalFOO
, gotBAR
instead HOWEVER if I use "action: Action" instead of {type, foo} is works.type State = {}; type FooAction = { type: "FOO", foo: string }; type BarAction = { type: "BAR", foo: boolean };
type Action = FooAction | BarAction;
function reducer(state: State, {type, foo}: Action): any { switch (type) { case "FOO": return { ...state, foo }; case "BAR": return { ...state, foo }; default: return state; } }
// Errors
9: function reducer(state: State, {type, foo}: Action): any { ^ string literal
BAR
. Expected string literalFOO
, gotBAR
instead 9: function reducer(state: State, {type, foo}: Action): any { ^ string literalFOO
9: function reducer(state: State, {type, foo}: Action): any { ^ string literalFOO
. Expected string literalBAR
, gotFOO
instead 9: function reducer(state: State, {type, foo}: Action): any { ^ string literalBAR
9: function reducer(state: State, {type, foo}: Action): any { ^ boolean. This type is incompatible with 9: function reducer(state: State, {type, foo}: Action): any { ^ string 9: function reducer(state: State, {type, foo}: Action): any { ^ string. This type is incompatible with 9: function reducer(state: State, {type, foo}: Action): any { ^ boolean 11: case "FOO": return { ...state, foo }; ^ string literalFOO
. This === check always fails becauseFOO
is not the same string asBAR
9: function reducer(state: State, {type, foo}: Action): any { ^ string literalBAR
// Error https://flow.org/try/#0PTAEAEDMBsHsHcBQiAuBPADgU1AZRQIYo4C8oA3gL4DcqmOAYrLAIIDGKAlrAHahnlQ6bAC5QAIgYB5KeIA0oSMzEBnFACdOPAOagadbKABCBdey69+FIfTHijLAErzFy0ACNm0LAT76DOObcfGRMrBzBoAA+xqZBvLSIkACuPBGW6lgAJslsWOoAFGpEWGL4JQrkwlgKSrCUYvE8AJRivmgUiKCgKvCcKGwAFqAF1c2d3d1sBCo4kjLiYpkoyep8ggB0W8XEtcx6tJOg07MSDs5LWCtr1lsbOzWusAddk1lYkATJ0Cgir0fLVZ8B6HPSISjIIA
// Works
https://flow.org/try/#0PTAEAEDMBsHsHcBQiAuBPADgU1AZRQIYo4C8oA3gL4DcqmOAYrLAIIDGKAlrAHahnlQ6bAC5QAIgYB5KeIA0oSMzEBnFACdOPAOagadbKABCBdey69+FIfTHijLAErzFy0ACNm0LAT76DOObcfGRMrBzBoAA+xqZBvLSIkACuPBGW6lgAJslsWOoAFGpEWGL4JQoE6Txi8TwAlGK+aBSIoKAq8JwobAAWoAVVFjwAdMJY9a3t7WwEKjiSMuJimSjJ6nyCI9vFxApKsE3VIwd6tNOgs-MSDs4rWGsb1tsju1j7bkPBJ8xnbdNZLCQAjJaAoET-C6rdZ8N7nPSISjIIA