gcanti / io-ts-codegen

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

`printRuntimeInterfaceCombinator` doesn't propagate `name` to `intersectionCombinator` #31

Closed gabejohnson closed 5 years ago

gabejohnson commented 5 years ago

While attempting to give custom names to my types, I noticed that some of my codices receive the name, while others do not. It turns out that those with optional properties are the ones that don't.

I believe I've tracked this down to https://github.com/gcanti/io-ts-codegen/blob/30f6374b08ab0fc2928f6b66185f266d84132258/src/index.ts#L600-L610

Notice that ic.name is not being passed down intersectionCombinator.

I can submit a PR if you'd like.

gabejohnson commented 5 years ago

The problem occurs a few lines down with partialCombinator https://github.com/gcanti/io-ts-codegen/blob/30f6374b08ab0fc2928f6b66185f266d84132258/src/index.ts#L612-L614

gabejohnson commented 5 years ago

https://github.com/gcanti/io-ts-codegen/blob/30f6374b08ab0fc2928f6b66185f266d84132258/src/index.ts#L703-L707

It may be worth passing name to t.readonly as well.

gcanti commented 5 years ago

@gabejohnson good catch, thanks for the bug report!

It may be worth passing name to t.readonly as well

Maybe, I'm not sure about that. IMO I should drop the isReadonly boolean and add an explicit ReadonlyCombinator

gcanti commented 5 years ago

I should drop the isReadonly boolean and add an explicit ReadonlyCombinator

@gabejohnson in the meanwhile which name should I use for t.readonly in your opinion? declaration.name?

gabejohnson commented 5 years ago

which name should I use for t.readonly in your opinion? declaration.name?

That was my thinking

gcanti commented 5 years ago

@gabejohnson released a patch, let me know if it works for you

gabejohnson commented 5 years ago

Thanks for addressing this so quickly!

gabejohnson commented 5 years ago

Maybe, I'm not sure about that. IMO I should drop the isReadonly boolean and add an explicit ReadonlyCombinator

I agree

gcanti commented 5 years ago

@gabejohnson https://github.com/gcanti/io-ts-codegen/releases/tag/0.3.2