Typescript generic extends show error message. (unexpected token, ...)

Viewed 766

I'm trying to extends Union type. But, it show me an error message.

In other project, there is no problem.

Are there anyone who know about this error?

type Foobar = 'foo' | 'bar';

interface OptionProps<T extends Foobar> {
                        ~~~~~~~ // Parsing error: Unexpected token, expected ","
                                   1 | type Fb = 'foo' | 'bar';
                                   2 |
                                 > 3 | interface OptionProps<T extends Fb> {
                                     |                         ^
                                   4 |   value: T;
                                   5 |   setValue: (value: T) => void;
                                   6 | }eslint

  value: T;
  setValue: (value: T) => void;
}
2 Answers

In eslintrc.json check that you have parser set to this:

"parser": "@typescript-eslint/parser",

If its set up right just delete node_modules and run npm install.

rm -rf node_modules/
npm install

I see no error when using it

type Foobar = 'foo' | 'bar';

interface OptionProps<T extends Foobar> { 
  value: T;
  setValue: (value: T) => void;
}

TypeScript Playground

Try re-compiling your code

Related