Expression expected error on logical operator after checking if instanceof GenericClass<T>
See original GitHub issuePrettier 2.7.1 Playground link
--parser typescript
Input:
export class Foo<T> {
}
function sample(error: unknown) {
if (!(error instanceof Foo<'some-type'> || error instanceof Error) || !error.message) {
return 'something';
}
}
Output:
SyntaxError: Expression expected. (5:43)
3 |
4 | function sample(error: unknown) {
> 5 | if (!(error instanceof Foo<'some-type'> || error instanceof Error) || !error.message) {
| ^
6 | return 'something';
7 | }
8 | }
Expected behavior:
3 |
4 | function sample(error: unknown) {
5 | if (
6 | !(error instanceof Foo<'some-type'> || error instanceof Error) ||
7 | !error.message
8 | ) {
6 | return 'something'
7 | }
8 | }
~It works if I wrap Foo<‘some-type’> with parentheses and then prettier formats it like expected behavior (also removes ( )
) but I think it should work without wrapping.~ edit: problem occured again on reformat (obviously)
It works if I split that logical OR into separate statements (I know this is not logically the same as above, just for an example)
!(error instanceof Foo<'some-type'>) ||
!(error instanceof Error) ||
!error.message
Issue Analytics
- State:
- Created 10 months ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
Release v2.8 · Issue #13792 · prettier/prettier - GitHub
Run on other projects to check for regressions v2.8.0 ... Expression expected error on logical operator after checking if instanceof ...
Read more >instanceof - JavaScript - MDN Web Docs
The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object.
Read more >Error in using instanceOf operator in Java - Stack Overflow
If there is a field ID , I assume that it is there to identify the employee. In that case, it must be...
Read more >instanceof
The instanceof operator tests whether the prototype property of a constructor appears anywhere in the prototype chain of an object.
Read more >Programming With Java Generics - Angelika Langer
Here is a typical beginner's mistake for illustration. ... One of these situations are type checks (i.e., cast or instanceof expressions).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Expressions like
Foo<'some-type'>
are called instantiation expressions, so the place for the test istests\format\typescript\instantiation-expression
Maybe
tests/format/typescript/logical-expression
(not-exist yet) is a better place.