how to fix typescript eslint error: Parsing error: Type expected

Viewed 543

typescript support string literal union type from enum,but eslint with error,how to fix??

enum Kind {
  'info' = 'info',
  'positive' = 'positive',
  'negative' = 'negative',
  'warning' = 'warning',
}
export type KindType = `${Kind}`;

eslint error in export type KindType = ${Kind};

{
    "owner": "eslint",
    "message": "Parsing error: Type expected.",
    "source": "eslint"
}
1 Answers

So you can directly export the enum from the file. This approach can be helpful

export enum Kind {
  'info' = 'info',
  'positive' = 'positive',
  'negative' = 'negative',
  'warning' = 'warning',
}

Now you can import it in your other files, And use them accordingly.

import {Kind} from "./main"

Kind.info

Happy coding.

Related