mercredi 22 mai 2019

Is there a standard way to automate testing of typescript compile-time constructs like mapped-types?

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