-
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
'this' type inference from assignments to prototype properties in TypeScript #13013
Comments
We have the option of typing the value of I don't know if there's an easy way to ensure that all your functions have their |
@DanielRosenwasser thanks for your fast answer! can you show with this example?
|
interface IExample {
_variable: number;
initialize (): void;
}
function Example(this: IExample) { this.initialize.apply(this, arguments); }
Example.prototype.constructor = Example;
Example.prototype.initialize = function (this: IExample) {
this._variable = 10;
}; This is how I would do it @niokasgami -- not sure if Daniel was inferring something beyond this. |
wow thanks @Aarilight ! |
If you use However, it doesn't track assignments outside the constructor function, so it doesn't know about |
This is reasonably-well supported in JS and I don't think we're going to make future improvements to prototype-assignment-based classes in TS |
(In any case, this issue was fixed some time in 2017 or 2018.) |
So I was working with a Library (Rpg Maker MV One's) who's really ES5.
I realized that you can still use Es5 code and this cool!
The problem is when declaring intellisenses on function who have "this" variable or instance variables.
It's will not throw errors but it's kinda hard to declare the type of the variables
TypeScript Version: 2.1.1
Code
SO my suggestion was if this was possible to implement a option who permit to infering the "this" variable type by doing a code like this in function who use prototype like in ES5
this._aNumber: number = 10;
The Reason I'm doing Es5 is because it's common practice to not "wreck" out the Library that we works.
I could works with Pure Es5 but I love Typescript and I'm trying to find a good "inBetween" for it.
thanks for your further answer!
The text was updated successfully, but these errors were encountered: