gcanti / io-ts

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

Partial of a type should succeed if a specified prop is of the wrong type instead of fail #640

Open kylegoetz opened 2 years ago

kylegoetz commented 2 years ago

Consider

const A = t.partial({
  foo: t.string
})
A.decode({ foo: 5 }) // Left

I think instead of should be Right with the value contained inside {} because { foo: 5 } is of type Partial<{ foo: string }> isn't it?

Or is there something else that evaluates like this that isn't called partial?

enricopolanski commented 2 years ago

The behavior is correct and consistent with TypeScript's Partial utility type.

Partial basically transforms key: A to key: A | undefined or key?: A.

interface Foo {
  foo: string
}

const partialFoo: Partial<Foo> = {foo: 4} //Type 'number' is not assignable to type 'string'