jeudi 5 juillet 2018

Testing for TypeScript type checking failures

When I write a TypeScript library with generic constraints, I'd like to be able to specify tests of code that should type check and code that should not (because, say, I want to make sure the type checker is catching things that wouldn't satisfy a constraint correctly).

I haven't found a solution in conventional unit testing libraries (since the tests for failures wouldn't compile in the first place). I think I saw some examples of this deep in the TypeScript test suite where they either used file naming or comments to indicate assertions, but I can't find them now, and I couldn't unravel how the test runner worked for such a large project anyway. Googling is hard too: every combination of terms I've thought about brings back links about things like type guards or bug reports about TypeScript itself.

I know I could rig up a bash script that just runs tsc over the files and asserts that they fail, but I'd prefer the ability to match on specific compilation failures if possible. Any ideas?

Aucun commentaire:

Enregistrer un commentaire