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?
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With