microsoft/dtslint

Writing tests that fail differently in different typescript versions

alex-bolenok-centralreach opened this issue · 0 comments

How do I write tests where types fail as expected in different typescript versions but on different lines, depending on the version?

Here's some code:

interface A {
    str: string
}

const a: A = { // fails on this line in ts < 3.0
    str: 1 // fails on this line in ts >= 3.0
}

This fails on different lines depending on the TypeScript version.

DefinitelyTyped checks against multiple TypeScript versions, so no matter where I put the $ExpectError, the test as a whole will fail.

I can work around this problem by creating a variable from the literal first and assigning it to A1 later, or by disabling prettier and forcing everything on a single line, but I was hoping for a cleaner solution.

Is there maybe some kind of flag for $ExpectError which would specify a TypeScript version?

If not, should we make one?