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 only catch that it doesn't say it returns non-null value.
consta=getNonNull({a:null},"a");// a : null
I am trying to improve function to set 'obj' as an object of type [K in string]: U | null | undefined and then TypeScript would return 'U'.
Unfortunately TypeScript doesn't like it and types 'U' as '{}' instead of correct type.
functiongetNonNull<U,Textends{[Kinstring]: U|null|undefined},KextendskeyofT>(obj: T,key: K): T[K]{constv=obj[key];if(v!=null){// error TS2322: Type 'T[K]' is not assignable to type 'U'.// Type 'U | null | undefined' is not assignable to type 'U'.// Type 'undefined' is not assignable to type 'U'.returnv;}else{throw"A";}}
Do I miss something ?
The text was updated successfully, but these errors were encountered:
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
I have a simple code which checks property for null and throws exception if it is null or returns the value.
The only catch that it doesn't say it returns non-null value.
I am trying to improve function to set 'obj' as an object of type [K in string]: U | null | undefined and then TypeScript would return 'U'.
Unfortunately TypeScript doesn't like it and types 'U' as '{}' instead of correct type.
Do I miss something ?
The text was updated successfully, but these errors were encountered: