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
typeTargetProps={foo: string,bar: string};constmodifier=<TextendsTargetProps>(targetProps: T)=>{let{bar, ...rest}=targetProps;letresult: typeofrest&{bar: string}// 'foo' doesn't exist rest.foo;// Type 'Pick<T, Exclude<keyof T, "bar">> & { bar: string; }' is not assignable to type 'T'.letcombined: T=result;};
Expected behavior:
Rest properties of an object, which has a generic type, should be accessible after the spread operator was applied.
Actual behavior:
None of the properties described in the base TargetProps type can be accessed.
@weswigham I'm just curious, why the Pick/Exclude combination, when used in a conditional type, yields different result?
typeTargetProps={foo: string,bar: string};typeOmit<T,KextendskeyofT>=TextendsT ? Pick<T,Exclude<keyofT,K>> : never;constfn=<TextendsTargetProps>(obj: T): void=>{letrest: Omit<T,'bar'>;// 'foo' exists.rest.foo;// Although it's still not possible to restore the type of T.letrestored: T={bar: '',
...rest};// Type casting doesn't work either.letrestored2: T={bar: '',
...rest}asT;};
@DanielRosenwasser I just realized, that if some properties of the instantiated value may have a literal type, then we shouldn't be able reassign any of them.
That is, following example should probably raise an error: #28952 (comment)
P.S. sorry for linking to my own comment. Didn't really know where to ask this.
I have a fix for the first error in the original example that I will be putting up shortly. The second error in the original example in a duplicate of #28884.
TypeScript Version: 3.3.0-dev.20181201
Search Terms:
Code
Expected behavior:
Rest properties of an object, which has a generic type, should be accessible after the spread operator was applied.
Actual behavior:
None of the properties described in the base
TargetProps
type can be accessed.Playground Link: link
Related Issues:
The text was updated successfully, but these errors were encountered: