You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
please make sure to use simple string literal assignment with const. This limitation is coming from the type-system, because all the dynamic string operations (e.g. string concatenation, template strings and also object used as a map) will widen the literal type to its super-type, string. As a result this will break contextual typing for action object in reducer cases.
The text was updated successfully, but these errors were encountered:
huan
added a commit
to wechaty/ha
that referenced
this issue
May 3, 2020
There's another case related to this issue, is that the codebase can be passed the TSC but not be able to run by ts-node: TypeStrong/ts-node#391 (comment)
The reason is that ts-node will not load types.d.ts by default, we have to specify it explicitly in our ts file:
/// <reference path="./types.d.ts" />
huan
added a commit
to wechaty/ha
that referenced
this issue
May 4, 2020
When we define the redux action types in ducks, we will store them in a
types.ts
file:Use
export const TEST
And use
import * as types from './types'
in other TS module to import all the types.In this way, the
TEST
can keep the string literal type asmodule/TEST
, which is necessary for future usage.Do NOT use
export default { TEST }
In this way, the
typeof TEST
will becomestring
, which will lose its string literal type.If it lists its string literal type, then it seems more likely will cause the problem in future usage.
References
Using string constants as action type property:
The text was updated successfully, but these errors were encountered: