superstruct icon indicating copy to clipboard operation
superstruct copied to clipboard

Infer using lazy() creates `any` type.

Open j opened this issue 4 years ago • 2 comments

I'm unable to infer a type based off an object:

const ContainerNode = object({
  key: string(),
  selector: string(),
  children: lazy(() => ContainerNode),
  array: optional(boolean())
});

export type ContainerNode = Infer<typeof ContainerNode>; // = any

Removing children works as expected.

j avatar May 12 '21 23:05 j

I just noticed documentation states that this is a thing. It'd be cool to somehow force the type when using "Describe" mode. as well.

With the inverse Describe method, you have to disable strict null checking for it to work.

j avatar May 13 '21 00:05 j

I think this is likely a limitation of TypeScript.

ianstormtaylor avatar May 13 '21 12:05 ianstormtaylor