gcanti / io-ts

Runtime type system for IO decoding/encoding
https://gcanti.github.io/io-ts/
MIT License
6.67k stars 331 forks source link

record typings broken when domain is a branded type #360

Open brabeji opened 5 years ago

brabeji commented 5 years ago

Hello @gcanti, I think we may have found a bug in record type.

🐛 Bug report

Current Behavior

https://codesandbox.io/s/frosty-ellis-lynyt?module=/src/index.ts

image

image

Expected behavior

The branded type domain should be typed as string.

Reproducible example

https://codesandbox.io/s/frosty-ellis-lynyt?module=/src/index.ts

Suggested solution(s)

Fix typings of record

Your environment

Software Version(s)
io-ts 2.0.1
fp-ts 2.0.5
TypeScript 3.3.3

We <3 io-ts, thank you!

DenisFrezzato commented 4 years ago

This is actually an "issue" with the type system, check this out https://github.com/microsoft/TypeScript/issues/15746#issuecomment-301922834.

The current behavior or Record takes the known literal types in K, which in this case is the empty set and creates a type for you, and the resulting type is {}.