-
Notifications
You must be signed in to change notification settings - Fork 12k
wrong scope for async class member #6549
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
I am not sure to fire this issue to angular, webpack, of typescript repo. Please correct me if I post it in the wrong place. |
Have you tried using version 1.1 of the CLI? It fully supports Typescript 2.3. |
@beenotung You have to initalize the class before you can make use of it. Changing |
@sumitarora that is typo in the example, it's called correctly in the actual code base |
It seems due to the leaky class method. Example: class Animal {
name: string;
constructor(name){
this.name = name;
}
speak(x){
return `Hi ${x}, I am ${this.name}`;
}
}
const dog = new Animal('dog');
const xs = [1, 2];
const res = xs.map(dog.speak); The first guess of ["Hi 1, I'm dog", "Hi 2, I'm dog"] The real value of ["Hi 1, I'm undefined", "Hi 2, I'm undefined"] The 'correct' ways: xs.map(dog.speak.bind(dog))
xs.map(x => dog.speak(x)) So it seems not related to any compilers, this issue can be closed. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)Versions
Output of
ng --version
:Operation System: Archlinux x64
Output of
uname -a
:Repro steps.
ng new name
ng build
(no compile-time error is generated)The log given by the failure.
It seems to fail because of the
this
is not the owner of the prototype but function passed to the generator.Desired functionality.
The compiler shall use a variable to reference the scope and replace the usage of 'this'. An example of generated code:
It should return a promise of 'bar' in above example without error.
Mention any other details that might be useful.
Sample of output bundled js
Notice there is a function at line 2 (instead of arrow function) and the
this
at line 6 is not escaped.The text was updated successfully, but these errors were encountered: