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

[TypeScript 3.7] add support for nullish coalescing operator #6609

Closed
RIP21 opened this issue Oct 6, 2019 · 3 comments · Fixed by #6657
Closed

[TypeScript 3.7] add support for nullish coalescing operator #6609

RIP21 opened this issue Oct 6, 2019 · 3 comments · Fixed by #6657
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. scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency

Comments

@RIP21
Copy link

RIP21 commented Oct 6, 2019

Prettier 1.18.2

Input:

const a = null
console.log(a ?? "keque")

Output:

[error] src/index.tsx: SyntaxError: Expression expected. (8:16)
[error]    6 | 
[error]    7 | const a = null
[error] >  8 | console.log(a ?? "keque")
[error]      |                ^
[error]    9 | 

Expected behavior:
Should understand or at least ignore such expression.

@RIP21
Copy link
Author

RIP21 commented Oct 6, 2019

This one comes along with Optional Chaining #6595. I wanted to be sure that this one is not overlooked.
Sure, TS 3.7 is still in beta, but having this supported before the official release will be awesome :)

@sosukesuzuki sosukesuzuki added the lang:typescript Issues affecting TypeScript-specific constructs (not general JS issues) label Oct 7, 2019
@thorn0 thorn0 changed the title [TypeScript] Nullish coalescing operator is not supported (Expression expected error) [TypeScript 3.7] add support for nullish coalescing operator Oct 9, 2019
@thorn0 thorn0 added the scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency label Oct 17, 2019
@vernondegoede
Copy link

I've updated Prettier to 1.19.0, but I'm still getting errors when formatting files containing nullish coalescing statements.

SyntaxError: Expression expected. (32:53)
  30 | 
  31 | const MethodIcon: React.FC<Props> = ({ method, size = "default" }) => {
> 32 |   const methodIcon = PAYMENT_METHOD_IMAGES[method] ?? require("assets/images/payment-methods/unknown.png");
     |                                                     ^
  33 |   const iconStyle =
  34 |     size === "large"
  35 |       ? [styles.methodImage, styles.methodImageLarge]
    at e (/Users/vernon/Sites/expo/mollie/node_modules/prettier/parser-typescript.js:1:267)
    at Object.parse (/Users/vernon/Sites/expo/mollie/node_modules/prettier/parser-typescript.js:1:2261711)
    at Object.parse$2 [as parse] (/Users/vernon/Sites/expo/mollie/node_modules/prettier/index.js:10629:19)
    at coreFormat (/Users/vernon/Sites/expo/mollie/node_modules/prettier/index.js:13888:23)
    at format (/Users/vernon/Sites/expo/mollie/node_modules/prettier/index.js:14146:73)
    at formatWithCursor (/Users/vernon/Sites/expo/mollie/node_modules/prettier/index.js:14162:12)
    at /Users/vernon/Sites/expo/mollie/node_modules/prettier/index.js:42756:15
    at Object.format (/Users/vernon/Sites/expo/mollie/node_modules/prettier/index.js:42775:12)
    at performFormat (/Users/vernon/Library/Application Support/JetBrains/Toolbox/apps/WebStorm/ch-0/192.7142.35/WebStorm.app/Contents/plugins/prettierJS/prettierLanguageService/prettier-plugin.js:62:29)
    at PrettierPlugin.handleReformatCommand (/Users/vernon/Library/Application Support/JetBrains/Toolbox/apps/WebStorm/ch-0/192.7142.35/WebStorm.app/Contents/plugins/prettierJS/prettierLanguageService/prettier-plugin.js:36:16)
Process finished with exit code -1

@lydell
Copy link
Member

lydell commented Nov 9, 2019

@vernondegoede Your example seems to work:

Prettier 1.19.0
Playground link

--parser typescript

Input:

const MethodIcon: React.FC<Props> = ({ method, size = "default" }) => {
    const methodIcon = PAYMENT_METHOD_IMAGES[method] ?? require("assets/images/payment-methods/unknown.png");
}               

Output:

const MethodIcon: React.FC<Props> = ({ method, size = "default" }) => {
  const methodIcon =
    PAYMENT_METHOD_IMAGES[method] ??
    require("assets/images/payment-methods/unknown.png");
};

Please open a new issue if you find a bug. First, triple-check that the Prettier that is running actually is the version you think it is.

@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Feb 8, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Feb 8, 2020
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. scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency
Projects
None yet
5 participants