mozilla / node-convict

Featureful configuration management library for Node.js
Other
2.34k stars 146 forks source link

"Type instantiation is excessively deep and possibly infinite" when using default: null #402

Open noisyscanner opened 2 years ago

noisyscanner commented 2 years ago

Problem

As per the FAQ, we can make things required by setting default: null, if null is not a valid value.

With TypeScript I get the error Type instantiation is excessively deep and possibly infinite when trying to config.get any value, if somewhere in the schema there is default: null.

typescript 4.6.3 convict 6.2.1 @types/convict 6.1.1

(all versions latest at time of writing)

Repo here

https://github.com/noisyscanner/convict-issue Run yarn build to see the following

image
viliamsevela commented 2 years ago

Yep, same here.

TzachiSh commented 1 year ago

+1

heidimao commented 1 year ago

Is this issue resolved? We also experience the same?

justinasfour04 commented 1 year ago

Is it resolved. Can't use undefined or null for default

justinasfour04 commented 1 year ago

I found a solution, you have to cast your default to a type you want such as as string and the Type instantiation is excessively deep and possibly infinite error goes away. The reason this happens is that undefined | null point to the 'any' type. The recursive type defined that works to get the PathValue aka the type that get() returns can't find an end because of any. The type checker therefore thinks that you have an infinite recursion.