You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import*asReactfrom"react";constemptyMessage=<div>empty</div>;constlength=0;consttotalItemsCount=10;constgetPlural=(...args: any[])=>"";consta=(<div><div>{length ? emptyMessage : (<span>
Всего {totalItemsCount}{" "}{getPlural(totalItemsCount,["услуга","услуги","услуг"])} в этом
разделе
</span>)}</div></div>);
after applying prettier on this code we have:
import*asReactfrom"react";constemptyMessage=<div>empty</div>;constlength=0;consttotalItemsCount=10;constgetPlural=(...args: any[])=>"";consta=(<div><div>{length ? (emptyMessage) : (<span>
Всего {totalItemsCount}{" "}{getPlural(totalItemsCount,["услуга","услуги","услуг"])} в этом
разделе
</span>)}</div></div>);
As we see prettier added a parenthesis around emptyMessage which shouldn't affect parsing since this is a valid syntax. But typescript reports error:
[ts] A function whose declared type is neither 'void' nor 'any' must return a value.
The interesting part here, that if we simplify else part it will start work again:
import*asReactfrom"react";constemptyMessage=<div>empty</div>;constlength=0;consttotalItemsCount=10;constgetPlural=(...args: any[])=>"";consta=(<div><div>{length ? (emptyMessage) : (<span>{getPlural(totalItemsCount,["услуга","услуги","услуг"])} в этом
разделе
</span>)}</div></div>);
It appears enough to remove first line Всего {totalItemsCount}{" "} inside span where we have string literal, and 2 expressions.
I tried to change this first line in different combinations (just literal, just expressions, etc) but only complete removal of this exact line helps. o_O
TypeScript Version: 2.9.0-dev.20180515
Search Terms: ternary, ternary tsx
Code
Here is working code
after applying prettier on this code we have:
As we see prettier added a parenthesis around
emptyMessage
which shouldn't affect parsing since this is a valid syntax. But typescript reports error:The interesting part here, that if we simplify else part it will start work again:
It appears enough to remove first line
Всего {totalItemsCount}{" "}
inside span where we have string literal, and 2 expressions.I tried to change this first line in different combinations (just literal, just expressions, etc) but only complete removal of this exact line helps. o_O
Expected behavior: Compile in any case above
Actual behavior: Some cases led to parsing error
Playground Link: https://codesandbox.io/s/3z83kpxp1 (hit Prettify icon in top right corner under profile menu)
Related Issues: #16241
I am starting issue here and not in prettier repo, since I am sure that all snippets above are valid syntax,
The text was updated successfully, but these errors were encountered: