I am new to TypeScript and saw the following in the @types/prop-types package. What does -?
mean in [K in keyof T]-?
?
export type ValidationMap<T> = { [K in keyof T]-?: Validator<T[K]> };
Similarly, what does -readonly [K in keyof T]?
mean in immer?
export type WritableDraft<T> = {-readonly [K in keyof T]: Draft<T[K]>}
I tried my best to google that, but failed.
Homomorphic mapped types copy the optionality of the original type field to the mapped type field. The -?
is the syntax used to explicitly remove any optional modifier from the resulting mapped type.
Similarly, -readonly
removes the "readonlyness".
You can read more details here.