@andy-ms
Has there been any discussion of adding a test file with code that doesn't compile? Let's say I write the types for a package foo in some way like this:
export function bar(arg: number);
I would like to be able to add a test like this
import { bar } from 'foo';
bar('wrong'); // tsc-error: Argument of type .* is not assignable to parameter of type 'number'
Where the comment signifies that there should be an error matching the regex provided.
This would help make sure that the type definitions are actually useful - that they prevent invalid use of the library.
Should be possible using the api shipped with typescript.
There is some functionality like that available in dtslint, so as long as you're linting your code (enabled by adding a tslint.json containing { "extends": "dtslint/dt.json" }) you can add // $ExpectError to a line where you expect an error.
Good enough for me!
Most helpful comment
There is some functionality like that available in dtslint, so as long as you're linting your code (enabled by adding a
tslint.jsoncontaining{ "extends": "dtslint/dt.json" }) you can add// $ExpectErrorto a line where you expect an error.