Skip to content
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

Number properties can't be unquoted in TypeScript #10123

Closed
remcohaszing opened this issue Jan 24, 2021 · 3 comments · Fixed by #10126
Closed

Number properties can't be unquoted in TypeScript #10123

remcohaszing opened this issue Jan 24, 2021 · 3 comments · Fixed by #10126
Labels
lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:docs Issues about adding or improving documentation

Comments

@remcohaszing
Copy link

Prettier usually removes unnecessary quotes from properties in TypeScript and JavaScript. However, when a numeric property is used in TypeScript, they keep their original quoting.

I tried to see if the quotes make TypeScript behave differently using TypeScript 4.1.3, but it does not.

In the linked playground, the diffence can be observed when toggling the parser between babel and typescript.

Prettier 2.2.1
Playground link

--parser typescript

Input:

interface Foo {
  '42': string;
}

const foo = {
  '42': ''
};

Output:

interface Foo {
  "42": string;
}

const foo = {
  "42": "",
};

Expected behavior:

interface Foo {
  42: string;
}

const foo = {
  42: "",
};
@brodybits
Copy link
Contributor

See this comment: #8508 (comment)

I think this should be documented in the help text, at least.

@thorn0 thorn0 added the type:docs Issues about adding or improving documentation label Jan 24, 2021
@thorn0
Copy link
Member

thorn0 commented Jan 24, 2021

TS differentiates between string and numeric keys: https://www.typescriptlang.org/play?#code/DYUwLgBAhhC8EG8IEYBcKA0EBM7sQF8AoUSAIzkQgHJlr1ktrt6dCiiATEAY2CgBOICKWhR0AaxABPAPYAzCGGkAHEAugBuLr35CR4CGTKSZG5Wo1ltRKDHjHtQA

I think this should be documented in the help text, at least.

Okay, let's mark this issue as "docs".

@thorn0 thorn0 added the lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) label Jan 24, 2021
@thorn0 thorn0 changed the title Number properties should be unquoted in TypeScript Number properties can't be unquoted in TypeScript Jan 24, 2021
@remcohaszing
Copy link
Author

TS differentiates between string and numeric keys: https://www.typescriptlang.org/play?#code/DYUwLgBAhhC8EG8IEYBcKA0EBM7sQF8AoUSAIzkQgHJlr1ktrt6dCiiATEAY2CgBOICKWhR0AaxABPAPYAzCGGkAHEAugBuLr35CR4CGTKSZG5Wo1ltRKDHjHtQA

That’s weird, but it makes sense from the perspective of Prettier.

@github-actions github-actions bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Apr 27, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. type:docs Issues about adding or improving documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants