-
Notifications
You must be signed in to change notification settings - Fork 12.8k
tsc produces invalid typings for parameter destructuring #3912
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
Parameter names are required in some form or another. See #2023 for the bug about destructured parameters creating invalid .d.ts files |
Hey Ryan. I don't think this is a duplicate of #2023, as I'm not attempting to destructure anything here. Since parameter names are required (thank you for clarifying!), the issue is now that This was tested using the latest version of tsc, taken from master/bin/tsc. Some sort of error should be produced at compile-time instead of generating invalid output, right? |
You're right. Thanks for following up -- I misread the linked bug. |
Sadly, this is not a bug. The ES6 destructuring syntax is eerily similar to the syntax for object types. The following is perfectly valid ES6: function foo({ prop: boolean }) {
let x = boolean; // Destructuring declares local named boolean of type any
}
foo({ prop: 42 }); Not entirely clear how we'd make something like that an error. |
Just to clarify, the issue here is that the declaration file generated is not valid. there is an extra ":" emitted after "prop" in: interface SomeInterface {
({prop: }: {
prop: any;
}): any;
} |
Fix #3912: emit declaration for binding elements correctelly
I have an interface that is supposed to have a function signature of:
but I forget the parameter name (I'm not sure if this signature is considered valid):
When compiling this invalid interface with the
--declaration
flag, an invalid.d.ts
file results:tsc foo.ts --module commonjs --declaration
If parameter names are optional, this should produce a valid
.d.ts
file. If parameter names are required,tsc
should throw an error, or at least warn me that there is an issue.The text was updated successfully, but these errors were encountered: