-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Getting error TS2339: Property does not exist on type for a valid ES6 class #6373
Comments
|
Yes. As I mentioned the generated JS is a valid JS file. The issue here is developer experience. The error shows up in IDEs and also in the build output through GruntJS/GulpJS. This error breaks the notion of TypeScript being a superset of Javascript and any valid JS is a valid TS. |
Duplicate #766 |
Can it surely be a duplicate of the ticket called "Allow declaring class members within a constructor"? It is my understanding that in ES6, we do not declare data properties of classes. The problem introduced here (and causing troubles as early as step 2 in angular2 tutorial) is that for some reason TS requires data property declaration meanwhile stating it is a superset of ES6. |
@RyanCavanaugh any chance of reopening this issue? I agree with @mrnagydavid that this issue is not the same as #766 which proposes different methods for declaring class members within a constructor while the current one is about making a valid JavaScript code to work in a TypeScript project without generating any errors. The idea is to solve the problem of 'my ES6 code is an error in TypeScript' mentioned by @danquirk here: #766 (comment) without introducing new syntax but instead:
|
The Typescript Specification describes Typescript as superset of ECMAScript 2015 (ES2015) which supports all ES2015 features. Quote: "Every JavaScript program is also a TypeScript program." So it should definitely not error on valid JS-Code. Link: https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#1-introduction |
This is true of syntax and runtime semantics, but it is obviously not that TypeScript cannot add semantic errors. By your argument, we could not issue an error on things like |
I believe that this at least need be clarified in spec. When one reads "Every JavaScript program is also a TypeScript program" he/she can erroneously conclude that every program will run without any noticable additional effort which is not always the case. |
I am currently converting an ES6 project to typescript and in ES6 we can easily write |
hi gents. |
or a bit different version here : |
Anyone managed to get Array.from to work? http://stackoverflow.com/a/36719911/1339087 I'm still getting: |
use |
Thanks, I won't bother with that interface now thx |
This one is really annoying. Sometimes I want to have a class without cluttering it with type information. Maybe adding something like |
I have the following ES6 class
When compiled/transpiled through TypeScript it generates error TS2339: Property 'myclassvar' does not exist on type 'MyClass'.
If the above code snippet is valid ES6 then TypeScript should not generate the error. The generated javascript it valid. It's just that the error scares the developers trying to use ES6 without typings.
The same ES6 class transpiles properly in BabelJS.
I know I can fix the error by declaring the variable.
Since TypeScript is a superset of Javascript, it should be able to handle valid ES6 without errors.
My compiler settings are
The text was updated successfully, but these errors were encountered: