-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Closed
Labels
lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)Issues affecting TypeScript-specific constructs (not general JS issues)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!Code is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!Issues with an accompanying pull request. These issues will probably be fixed soon!
Milestone
Description
Prettier 1.12.1
Playground link
--parser typescriptInput:
class User {
"username": string;
}Output:
class User {
username: string;
}Expected behavior:
The output should be identical to the input:
class User {
"username": string;
}Otherwise, when the TypeScript code is compiled with --strictNullChecks and --strictPropertyInitialization (which are collectively set by default via the --strict flag), the type checker will raise a type error:
Property 'username' has no initializer and is not definitely assigned in the constructor.
This is because TypeScript's type checker treats properties with quoted names more leniently than unquoted ones. I suggest Prettier preserve quotes around property names in classes when using the TypeScript parser.
Steps to verify this behavior:
- Open this TypeScript playground.
- Click "Options" and enable both
strictNullChecksandstrictPropertyInitialization. - Note the type error.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)Issues affecting TypeScript-specific constructs (not general JS issues)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!Code is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!Issues with an accompanying pull request. These issues will probably be fixed soon!