-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Duplicate identifier in function declaration due to stripped property renames #50707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
#50537 fixed this by leaving the renames in if the name was a keyword, but now if the same property is destructured into two different names, the new names still have to be preserved again, too, to avoid an error. At this point, I'm wondering why we are even emitting these into |
Extra documentation is about the only reason. Autocomplete for callers is going to come from the type. |
I would propose preserving duplicates in 4.8.4 and then I’d be fine with emitting |
I've been looking into this; unfortunately it seems like the way that #41044 and #50537 operate make it prohibitively difficult to catch the the second case in the post: const fn = ({ prop: a }: { prop: number }, { prop: b }: { prop: number }) => a + b; The code that was modified is part of I think that we should just do a partial revert of #41044 (for both main and 4.8), removing the elision in |
I have a fix that does drop the binding patterns entirely, except it won't work because this is legal: function fn({ x }: { x: string }, y: typeof x): typeof x {
return x + y;
} If we drop the binding pattern indiscriminately, we can't refer to Also, it appears as though we error when we have a optional binding element parameter and the binding element is empty: declare function fn1({}?: { x: string }): void; // error
declare function fn2({ x }?: { x: string }): void; // OK?
declare function fn3([]?: [ x: string ]): void; // error
declare function fn4([ x ]?: [ x: string ]): void; // OK? This trips up at least one test case; this seems like a bug to me and I'll report it elsewhere. |
I've merged #50779 for now, which does fix this issue, but per the above I don't know if it's a good idea to do the empty binding element transformation. |
Bug Report
🔎 Search Terms
TS2300
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?#code/MYewdgzgLgBAZmGBeGAKA3jADgJxFgLhgEMAabPQmAIxgF8jNd8iwBXAW2oFMd6BKZAD4SMANQ0A3EA
💻 Code
Or alternatively:
🙁 Actual behavior
.D.TS on TypeScript 4.8.2:
https://www.typescriptlang.org/play?ts=4.8.2#code/MYewdgzgLgBAZmGBeGAKA3jADgJxFgLhgEMAabPQmAIxgF8jNd8iwBXAW2oFMd6BKZAD4SMANQ0A3EA
🙂 Expected behavior
.D.TS on TypeScript 4.7.4:
https://www.typescriptlang.org/play?ts=4.7.4#code/MYewdgzgLgBAZmGBeGAKA3jADgJxFgLhgEMAabPQmAIxgF8jNd8iwBXAW2oFMd6BKZAD4SMANQ0A3EA
The text was updated successfully, but these errors were encountered: