Say we're trying to implement the Pick
mapped-type:
type Pick<T, K extends keyof T> = {
[P in K]: T[P];
};
We should expect that any type built from this conforms to some typescript compile-time check. Is there a way to test that? Using a testing framework or otherwise?
type Foo = { foo: string, bar: string };
type TestType = Pick<Foo, 'foo'>;
// expect this to fail at compile time because of property 'bar'
let foo: TestType = { foo: 'foo', bar: 'bar' };
Aucun commentaire:
Enregistrer un commentaire