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

Bring back renamings in emitted d.ts files #55678

Closed
wants to merge 2 commits into from

Conversation

jakebailey
Copy link
Member

Fixes #55654 (with the unfortunate solution)

This isn't ideal. I think the direction we want to go is to not emit renamings if we don't have to, but the current implementation uses isReferenced which unfortunately considers references other than those that affect the signatures of the functions. So if you ever actually use the parameter you've renamed, then it will be kept, even if that isn't required. In the real world, that'd of course be nearly all instances, because there's usually no reason to destructure a parameter and then not use it. Of course our tests have a lot of this because we typically don't care about what's inside a function, or we don't have a body at all!

This with #50779 effectively reverts all of #41044 except the new error. You'll notice that this PR's baseline changes don't contain any new errors, which is good. This is because the error only happens when the signature doesn't have an annotation, e.g.:

declare function foo({ a: string }): void; // Error
declare function bar({ a: string }: { a: string }): void; // Okay!

The former can't happen in emitted d.ts files; we're always going to fully annotate the output.

Maybe there's a solution that would instead attempt to figure out if the name is ever actually used elsewhere, but I'm not sure how to do that. I feel like we probably have that logic somewhere for other reasons? In which case, I'm happy to redo the PR.

@andrewbranch
Copy link
Member

I can’t see from the conversation in #55654 why we need to do anything here 🤔

@jakebailey
Copy link
Member Author

No, you're right; we could "do nothing" and it would be fine; the existing code only removes things that are definitely unreferenced. If we want to do this right with usage tracking, that's #55683.

@jakebailey jakebailey closed this Sep 8, 2023
@jakebailey jakebailey deleted the fix-55654 branch September 8, 2023 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Binding element alias is kept even though it is unused in declaration files
3 participants