-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
In JS, constructor functions without property assignments aren't recognised as classes #18171
Comments
Hello! How do we write ES5 constructor classes in TypeScript? |
@trusktr This issue tracks detection of ES5 constructor functions in Javascript. For example, the original example works if you put To write an ES5 constructor function in Typescript, use function Class(this: { x: number }, x: number) {
this.x = x
}
var c = new Class(12) // this line is still an error in strict mode |
I noticed that TypeScript behaves differently when its input language is set to .js and fortunately the basic Unfortunately both |
#39447 fixes the original example and the one from @AlCalzone, so I think it's fair to close this bug. However, the fix doesn't do exactly what the bug title requests. The fix types Almost every constructor function will have methods or a prototype assignment (or this-property assignments), so it covers basically all constructor functions. @moll You are looking for #13206 or #36369 |
TypeScript Version: 2.5.1
Code
For the JS:
Expected behavior:
In the function
Foo
,this
is the type ofFoo
and you can rungo to definition
onthis.init
Actual behavior:
this
isany
.go to definition
does not work onthis.init
but does ona.init
The text was updated successfully, but these errors were encountered: