node-convict icon indicating copy to clipboard operation
node-convict copied to clipboard

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

Open noisyscanner opened this issue 3 years ago • 6 comments

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

noisyscanner avatar Mar 25 '22 11:03 noisyscanner

Yep, same here.

viliamsevela avatar Jun 14 '22 15:06 viliamsevela

+1

TzachiSh avatar Jan 11 '23 11:01 TzachiSh

Is this issue resolved? We also experience the same?

heidimao avatar Apr 13 '23 11:04 heidimao

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

justin-is-a-builder avatar May 23 '23 18:05 justin-is-a-builder

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.

justin-is-a-builder avatar Jun 01 '23 21:06 justin-is-a-builder