New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ts-ignore should error if next line is not an error #29394

Open
davidgomes opened this Issue Jan 13, 2019 · 7 comments

Comments

Projects
None yet
9 participants
@davidgomes
Copy link

davidgomes commented Jan 13, 2019

http://www.typescriptlang.org/play/#src=%2F%2F%20%40ts-ignore%0D%0Aconst%20a%3A%20number%20%3D%205%3B

In the example above, the @ts-ignore line should error because there is no TypeScript error to be ignored. This is the same behavior as Flow's suppress_comment feature.

Alternatively, if you want to maintain this behavior, consider creating a @ts-expect-error.

@rictic

This comment has been minimized.

Copy link
Contributor

rictic commented Jan 14, 2019

This is something that I often want when writing trickier library functions, and in DefinitelyTyped typings.

In the same way that you want to test that some inputs fail at runtime in your tests, it's desirable to be able to write tests that certain code will produce an error when compiled.

At present it's as though there's no way to assert that a function throws.

@kolodny

This comment has been minimized.

Copy link

kolodny commented Jan 15, 2019

This is very important for library authors to ensure that their types are valid. I've had to do some nasty stuff to ensure that fact without this feature

@RyanCavanaugh

This comment has been minimized.

Copy link
Member

RyanCavanaugh commented Jan 15, 2019

This is the intended behavior because one of the scenarios for ts-ignore is to allow the same code to work across multiple TS versions which may have slight differences between them.

https://github.com/Microsoft/dtslint supports "expecting" errors if that's your scenario.

It'd be good to hear more from you about what you'd like to use the different behavior for.

@Mouvedia

This comment has been minimized.

Copy link

Mouvedia commented Jan 15, 2019

This is about parity with Flow's $ExpectError.
$ExpectError has also been adopted by typings-checker.

@chrisblossom

This comment has been minimized.

Copy link

chrisblossom commented Jan 15, 2019

This would be very helpful/great for longterm maintenance of a project. Flow already can do this on their $FlowFixMe suppressions, and eslint can do this via the command line flag --report-unused-disable-directives or using plugin-eslint-comments/rules/no-unused-disable as well.

This is the intended behavior because one of the scenarios for ts-ignore is to allow the same code to work across multiple TS versions which may have slight differences between them.

I think this option should be opt-in behind a configuration flag so this shouldn't be an issue.

This would be even better in-combination with #19139 / #21197.

@TSMMark

This comment has been minimized.

Copy link

TSMMark commented Jan 16, 2019

My team is considering migrating to TS from Flow in 2019. We would love to see the functionality of $ExpectError in TS in order to continue to unit test our typings ❤️

@eps1lon

This comment has been minimized.

Copy link

eps1lon commented Jan 16, 2019

@TSMMark You can do this with tslint and the expect rule from dtslint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment