Skip to content
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

Illegal declaration file can be emitted (duplicate parameter names) when spreading tuples into parameter positions #53011

Closed
RyanCavanaugh opened this issue Feb 28, 2023 · 2 comments Β· Fixed by #53028
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Help Wanted You can do this
Milestone

Comments

@RyanCavanaugh
Copy link
Member

Bug Report

πŸ”Ž Search Terms

parameter spread duplicate identifier parameter tuple

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

function f() {
    // n.b. not illegal
    type C = [s: string, s: string]; 

    return function fn(...args: C) { }
}

Less-degenerate form where you can't just not make that mistake:

function f() {
    type A = [s: string];
    type C = [...A, ...A];

    return function fn(...args: C) { }
}

declaration emit in either case becomes

declare function f(): (s: string, s: string) => void;

which we consider a syntax error:

error TS2300: Duplicate identifier 's'.

1 declare function f(): (s: string, s: string) => void;

πŸ™ Actual behavior

Multiple parameters with the same name get printed

πŸ™‚ Expected behavior

Probably something like (s: string, s_0: string) => void instead

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this Domain: Declaration Emit The issue relates to the emission of d.ts files labels Feb 28, 2023
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 28, 2023
@fatcerberus
Copy link

Is there a reason this emits as (s: string, s: string) => void instead of (...args: [s: string, s: string]), preserving the original form of the definition?

IMO there's also a case to be made that, since the rest-param version is semantically equivalent to the separate parameters (enough so that decl emit will freely substitute one for the other), it should just be an error to use a tuple with duplicate labels.

Either way I'm a bit surprised nobody seems to have hit this before, tbh

@RyanCavanaugh
Copy link
Member Author

Is there a reason this emits as ...

Not particularly. You'd obviously want to see the former in something like signature help since it's easier to parse and highlight, and we largely share codepaths for type printback.

Either way I'm a bit surprised nobody seems to have hit this before, tbh

Me too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Help Wanted You can do this
Projects
None yet
2 participants