How to type immerable class
st-clair-clarke opened this issue Β· comments
st-clair-clarke commented
πββ Question
I have the following that is using Typescript strict environment.
export interface IUiState {
id: string
}
export class UiState {
id: string = nanoid()
}
UiState[immerable] = true
My IDE (Webstorm) generates a linting error from the statement RegistrationUiState[immerable] = true
as shown below:
TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'typeof
RegistrationState'. Property '["immer/dist/utils/env".DRAFTABLE]' does not exist on type 'typeof RegistrationState'.
How can I explicitly type the above to correct the issue?
Environment
We only accept questions against the latest Immer version.
- Immer version:
"immer": "^9.0.19",
"typescript": "^4.9.5",
"@angular/cli": "^15.2.2",
Michel Weststrate commented
You can use
export class UiState {
id: string = nanoid()
[immerable] = true
}
Michel Weststrate commented
Closing as answered