Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESLint complains TypeScript type declaration uses type before it was declared

I am creating a builder that has types, the way I declare the type is:

export type BuilderInterface<T> = {
  [key in keyof T]: (arg: T[key]) => BuilderInterface<T> } & {
  build(): T
}

When running ESLint it complains saying that: "BuilderInteface" was used before it was defined (no-use-before-define). What is normal since I need to assert that each argument functions returns a builder of the same kind.

Which ways do I have to declare this without breaking the eslint rule? Should I ignore the rule directly? Why?

like image 539
SirPeople Avatar asked Oct 11 '25 15:10

SirPeople


1 Answers

ESLint is (kind of) correct, because technically you haven't declared the type and you're using it. Recursive types are quite hard to handle. Try using TSLint to see if you get a better result as it understands TypeScript better.

The TypeScript team are pretty good at recursive types, so it's a valid type.

Disable the rule or create an exception so the tools let you get on with your job!

like image 173
Fenton Avatar answered Oct 14 '25 07:10

Fenton