-
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
Optional constructor arguments with accessors are being added to .d.ts as optional class members #8788
Comments
Optional class members are allowed now (#8625). Are you generating the file with one version of the compiler and consuming it with an older version? The provided generated snippet compiles without error in master. |
We are using it within Visual Studio so technically we're using tools version 1.8. Is there an updated version of the Visual Studio tooling? It compiles fine, just shows as an error in the Visual Studio Error List after compilation because it's in the generated .d.ts file. |
you can setup VS to use the latest nightly builds, see https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/Nightly%20Builds.md |
Thanks, I'll check it out. We're not currently using npm so we will just avoid the error for now and wait for the tooling installer. |
i think we have to fix this issue anyways. #8795 provides a compelling example of why |
closing in favor of #8795 |
TypeScript Version:
nightly (1.9.0-beta-20160521-3)
When creating a class, if a parameter is added to the constructor as optional and given an accessor (such as private), the compiler generates it as an optional class member in the .d.ts file which then throws a syntax error.
Expected Behavior
Either field would be added to the class and set with the optional parameter, meaning it could be null or undefined or a syntax error is displayed at compile time.
Actual behavior:
Parameter is added as an optional class field resulting in an error.
Example class declaration:
What The Compiler Produces in the Resulting .d.ts:
and the following error:
Error TS1112 A class member cannot be declared optional.
The text was updated successfully, but these errors were encountered: