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
{{ message }}
Repository navigation
When using generic pick, object deconstruction does not provide valid keys to select #45663
// We can quickly address your report if:// - The code sample is short. Nearly all TypeScript bugs can be demonstrated in 20-30 lines of code!// - It doesn't use external libraries. These are often issues with the type definitions rather than TypeScript bugs.// - The incorrectness of the behavior is readily apparent from reading the sample.// Reports are slower to investigate if:// - We have to pare too much extraneous code.// - We have to clone a large repo and validate that the problem isn't elsewhere.// - The sample is confusing or doesn't clearly demonstrate what's wrong.interfaceMapper<T=any,R=any>{(arg: T): R;}functionpick<O,TextendskeyofO>(keys: T[],obj?: O): Pick<O,T>;functionpick<T>(keys: T[]): Mapper;functionpick<O,TextendskeyofO>(keys: T[],obj?: O){constpicker: Mapper<O,{[KinT]: O[T]}>=_obj=>Object.entries(_obj).reduce((o,[key,val])=>{if(keys.includes(keyasT))o[keyasT]=val;returno;},{}asPick<O,T>);returnobj ? picker(obj) : picker;}const{ a, b }=pick(['b'],{a: 'a',b: 'b'})//here the autosuggest should show b onlyconstobj=pick(['b'],{a: 'a',b: 'b'})obj.a// here it is working properly as you can only select b
🙁 Actual behavior
When using the deconstruction construction after pick, I can select b as well as a. But the a is not in object returned from pick.
When first assigning the return value to const, in later code I can only select b, which is expected.
🙂 Expected behavior
In deconstruction I should be able to select only keys, that I declared in pick function. The behaviour should be same as in second example, where the return object is first assigned to obj var and then refered.
Activity
andrewbranch commentedon Sep 2, 2021
I think this is actually just a symptom of #43605
txantslusam commentedon Sep 21, 2021
Thanks Andrew Branch (@andrewbranch). It is working on nightly build on playground 🎉
andrewbranch commentedon Sep 22, 2021
Unfortunately the fix wasn't quite right and we decided to revert it and investigate more for next release—see #46009 and #46012