-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Binding element alias is kept even though it is unused in declaration files #55654
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
This comment was marked as outdated.
This comment was marked as outdated.
Bisects to #41044. |
I would have thought this was more a consequence of #50779 |
Me too! (I couldn't remember which PR that was) |
Is this a problem? Canβt |
Probably; I don't think there's much harm besides including an implementation detail, which is the main reason we were trying to drop them out of In #50779 I seemed to think I was going to send a follow-up to improve things but clearly I never did, but the fact that this was broken by #41044 and not #50779 is very interesting. (Also makes me think about #49627...) |
I've sent a "fix" at #55678 which just continues down the the path of reverting #41044; realistically in #50779 I should have fully undone the renaming removals but I don't think I noticed the additional code path doing the same thing in declaration emit. I bet there's some test case that would break in a similar manner to what was fixed in #50779 because of this problem. I don't know if this is ideal; obviously it'd be better to not emit renamings at all if we don't need them, but I'm not totally sure if we have the machinery in place to query "will I need this name somewhere else eventually in the emit". |
Of course, an alternative is to just "do nothing" and accept that this is a limitation of the declaration emit, and that adding it when it's unused is harmless. But as I said in #55678, if you're destructuring a parameter in your |
@jakebailey I mean it could emit |
Er, I thought we effectively found that typeof just can't be emitted with |
@jakebailey If it written by the user, it will be copied like any other type. Isolated declaration will never forbit an explicit annotation. It just won't try to synthesize it. Performing the usage analysis to determine what needs to be kept to make the I was looking at the code, and I think most of the necessary machinery to perform correct analysis is already there. I opened #55683 as a suggested fix. |
Yeah, this is what I suspected. I'm not convinced |
This is true, but the declarations emitted by TypeScript at present suffer from the same issue. The currently TSC generated declarations are: export declare const x: number;
export declare const y: {
x: typeof x;
}; Which don't account for the narrowing of If TSC decides to used the narrowed type at a later date, we can make the code above an isolated declaration error. There will continue to be cases when either the code contains semantic errors or the code contains isolated declaration errors that are not detectable in a DTE without type info (few hopefully) that would mean a DTE successfully generates declarations that TSC would refuse to generate. This would be such a case. |
I guess I just don't understand why destructured parameters have to be in the |
Scoping rules mean that |
π Search Terms
binding element alias declaration files
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play?ts=5.2.2#code/PTAEhRyUFgCgVAygCwPYFcA2ATUA7FALqAEYCmoA1qQA5ECGuOAlgM6gBOpAtigG6lZYAMzS4AxgSYpcoFqkxYAcoQDSpGqAAUAbzx0upAFyg6GJnTYBfY7tz6jsguya4A5qEsBKUNtih-0DCWsLDwgDLkoWAAgmYWoKygaCwC8TIESOQi4pLSJGhE+EQuoOnkLEyudgRonJGI8th4hCTkVLSpoFikYhh07HQ5uGxxTEXDMkxc1BjcpLgEA1IyXQtMGHUsAJ5cxCgYAHSsAEqkQqSc4ikJSSkA7khMYkigT90UbJxnF2Kk45v351I+2EogkS1kDSUqnU1AAQvkAJIsNTtHR6AzGUzmKw2dEOFhOFzuLy+GABDikarsGRYiywYIwOrgOoAVWSzBknCpaU21HImjE6EafNA1D69gI5zYBF5vxMbFupAwGG8LBQ8SIciFODIlBoBBB2XBWrQWAwag0aLsGJMsRxPjxxgJzjcHk8xhlfJQQlt2J8fgCXJqNLt9KAA
π» Code
π Actual behavior
alias
is kept in declaration files forshouldNotKeepButIsKept
π Expected behavior
Either
alias
is removed from declaration file forshouldNotKeepButIsKept
, oralias
is also kept forshouldNotKeep
.Additional information about the issue
Seems like declaration emit is using
isReferenced
of the symbol. But this tracks usage of the symbol anywhere in the scope, we would need usage of the symbol in the function signature.The text was updated successfully, but these errors were encountered: