Open huan opened 4 years ago
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: https://github.com/TypeStrong/ts-node/issues/391#issuecomment-315470585
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" />
We can use const o = {} as const
to keep the literal types.
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: