Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Writing tests that fail differently in different typescript versions #258

Open
alex-bolenok-centralreach opened this issue Oct 24, 2019 · 0 comments

Comments

@alex-bolenok-centralreach

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant