-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Function arguments desctructuring #4548
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
Which version of TS? |
Latest stable I believe. 1.5.3
|
In this example:
It showed "src\main.ts(15,17): error TS7005: Variable 'x' implicitly has an 'any' type." in 1.5.3 but now it is fixed in 1.7.0 And I don´t know what you can do with this
You can´t define explicit types in destructuring. That code says: " I expect two properties ( x and y ) but I rename them to number and number, respectively" |
How it might be fixed if I use "noImplicitAny"? It should warn as it does. Right, I cannot define type in destructuring, this is a problem. You may What I can do with that number properties? Use them as number variables, as
|
As you can´t define type in destructuring, It has no sense that compiler shows an error if you set noImplicitAny to true. I don´t think that is a bug. ES6 sintax uses " : " to rename property and it interferes with TS typed sintax.
Maybe could be...:
So, you can´t, for the moment Yeah, you can:
|
You can't have type annotations within a destructuring object literal because ES6 already defines a different meaning for function test({ x, y }: { x: number, y: number }) {
console.log(x, y);
}
test({
x: 1,
y: 2
}); See also #3828. |
This does not work. This is expected since I have
"noImplicitAny": true
:src\main.ts(15,17): error TS7005: Variable 'x' implicitly has an 'any' type.
src\main.ts(15,20): error TS7005: Variable 'y' implicitly has an 'any' type.
However,
function test({ x:number, y:number }) {
does not works too, whilefunction test({ x = 0, y = 0 }) {
works fine, but I do not want default params here. Is there a solution for it?The text was updated successfully, but these errors were encountered: