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
The new version of Omit discards the field modifiers. The solution is to avoid using a type directly in a keyof statement as TS loses the inference of the field modifiers (optional, readonly).
I am not sure if it should behave this way, as you looked confident writing the Omit type, it's probably part of another problem. In short, TS discards the inference of field modifiers on mapped types that map with another type (instead of keyof).
TypeScript Version: 3.5.0-dev.20190501
Search Terms:
mapped type readonly lose modifiers
Code
typeOmit<T,Kextendskeyofany>={[PinExclude<keyofT,K>]: T[P]}// ^^^^^^^^^^^^^^^^^^^^ optional & readonly not inferred// Mapping with a type like Exclude<keyof T, K> caused TS to forget modifierstypeO={readonlya: stringb?: numberc?: any}typetest00=Omit<O,'b'>typeWhatWeGet={a: string;c: any;}// === test00typeWhatItShouldBe={readonlya: string;c?: any;}// !== test00
Expected behavior:
Should preserve the modifiers
Actual behavior:
Loses the modifiers on the fields
Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered:
@DanielRosenwasser
The new version of
Omit
discards the field modifiers. The solution is to avoid using a type directly in akeyof
statement as TS loses the inference of the field modifiers (optional, readonly).I am not sure if it should behave this way, as you looked confident writing the
Omit
type, it's probably part of another problem. In short, TS discards the inference of field modifiers on mapped types that map with another type (instead of keyof).TypeScript Version: 3.5.0-dev.20190501
Search Terms:
mapped type readonly lose modifiers
Code
Expected behavior:
Should preserve the modifiers
Actual behavior:
Loses the modifiers on the fields
Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered: