gcanti / io-ts-codegen

Code generation for io-ts
https://gcanti.github.io/io-ts-codegen/
MIT License
156 stars 14 forks source link

Brands in recursive types result in interface being misplaced #40

Open mikesol opened 5 years ago

mikesol commented 5 years ago

Calling t.brandCombinator on a recursive feild results in something like this:

const Schema: t.RecursiveType<t.Type<Schema>> = t.recursion('Schema', () => t.brand(_Schema, (x): x is t.Branded<_Schema, XPropertiesBrand> => true, 'XProperties')
interface XPropertiesBrand {
  readonly XProperties: unique symbol
})

The interface is placed within the recurisve expression.

That happens because of this line: https://github.com/gcanti/io-ts-codegen/blob/0be18841a50ceb0a45ade7f4bf0d9b365e33018c/src/index.ts#L788

One idea for a fix: another function instead of printRuntime (ie printDefinitions) could be used to print this sort of thing.

gcanti commented 5 years ago

Calling t.brandCombinator on a recursive feild

@mikesol could you please post a small repro?