add new mapped type: Invert<T> ... I do not know, how to explain it in english, so i use code:
// proposal syntaxtypeInvert<T>={[PinkeyofT]?: T[P];[P? inkeyofT]: T[P];};// usagetypeOriginal={first: any;second?: any;}typeInverted=Invert<Original>;// type Inverted is threated as if declared like this:typeInverted={first?: any;// first is optional becasue it was required in Originalsecond: any;// second is required becasue it was optional in Original}example usage: react defaultProps - to ensure, that all optional props are declared.
typeSomeProps={name: string;point?: {x: number,y: number};}classSomeextendsReact.Component<SomeProps,void>{// proposal usagestaticdefaultProps: Invert<SomeProps>={// here i get compiler error if do not specify property 'point'};// current usage (worst)staticdefaultProps: any={// here i dont get any errors at all};// betterstaticdefaultProps: Partial<SomeProps>={// here i dont get any errors if i dont specify point// but at least get compiler error for typo...};// even betterstaticdefaultProps: {name?: string;point: {x: number,y: number}}={// here i get compiler error if do not specify property 'point' and for typo// but i was forced to create new type ...};}priority: really low, almost negative :) - but if it can be done and isnt too hard ...
add new mapped type:
Invert<T>... I do not know, how to explain it in english, so i use code:example usage: react defaultProps - to ensure, that all optional props are declared.
priority: really low, almost negative :) - but if it can be done and isnt too hard ...