-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
generics can only detect arrow function in object but not function expression #57572
Comments
An object method without an explicit You can verify this by annotating type C = <Methods, Attached extends (methods: Methods) => void>(options: {
methods: Methods;
attached: Attached;
}) => any;
var Component: C = () => {};
Component({
attached(methods) {
methods.bbb(); // ok
},
methods: {
bbb(this: unknown) {},
},
}); |
what if I need to use Type C to define bbb's "this" type,will this issue be solved or not? @Andarist |
You can even workaround this particular situation by reordering your type C = <Methods, Attached extends (methods: Methods) => void>(options: {
methods: Methods;
attached: Attached;
}) => any;
var Component: C = () => {};
Component({
methods: {
bbb() {}, // no `this` annotation!
},
attached(methods) {
methods.bbb(); // ok, yay!
},
}); |
ohhhhhhhh, I will try this, thanks |
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
🔎 Search Terms
typescript
generics
arrow function
function
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?#code/C4TwDgpgBAwlC8UA8AoK6oFkLABYHsATAZwBo0MBBYYAQwGNcJCEoAKAWxwJIC4tuRYgEoEAPigA3fAEtCKMWwrp8YYDPwA7YvwDeyjOi54h-bCZIBuA4do0GTQv2p1Gza4YC+KUfAm1NEGsUSVoAJ1h8DjAtCE1gfjhENl8JXShvFBgomM044DZ9W3s3Qk5BElEiwwxjHmIAOgAjFpSoAHp2qDww-AB3buIoCDDesINPckM60yhqmqgWprb07y8UT2EULJzY+MKDO1dHcosROZtaisalts6ofABrCamrs71L9CX+Nr85jImG2EQA
💻 Code
🙁 Actual behavior
Parameter "methods" in "attach" function should be functions declared in "methods" property, but it works only when function is arrow function.
🙂 Expected behavior
Parameter "methods" in "attach" function should be functions declared in "methods" property
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: