-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Comments
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. |
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 |
This is the intended behavior because one of the scenarios for 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. |
This is about parity with Flow's |
This would be very helpful/great for longterm maintenance of a project. Flow already can do this on their
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. |
My team is considering migrating to TS from Flow in 2019. We would love to see the functionality of |
@TSMMark You can do this with |
@RyanCavanaugh Understood from your comment why it is intentional that @ts-ignore does not cause an error when it is not "actively ignoring found error" (to support various versions of TypeScript, which might differ in whether or not they find an error there). I am also now moving from Flow to Typescript; new to Typescript. A really working $ExpectError would be good to have ($ExpectType could be nice as well). I have tried to make dtslint work on a code-base (couldn't). I could assume it might work for type tests in .d.ts files that contain purely type definitions / type tests and don't import anything. However, I couldn't make it work with files, where it is actually needed to test $ExpectError, like in unit tests, where types would be tested including type inference in code, etc. Dtslint would bail out with a heap of errors that it didn't like syntax in some node_modules (it wasn't possible to exclude those). Another reason why I didn't dig deeper in this is that I understand dtslint is built on top of tslint and from news I've read about the official switch from TSLint to ESLint for Typescript, so not sure if dtslint would keep working with new Typescript or not even if it worked now. A functional solution to be able to use $ExpectError in regular Typescript code (not only in definition files, where possibilities are limited) would be good to have - whether it would be directly in tsc or in a supported linter. This is something that works in Flow as described above |
Accepting PRs for the form // @ts-expect-error
const nope: string = 42; Note that this is a substantially different feature implementation-wise from |
Suggest updating the title of this issue to "Type correctness verification via @ts-expect-error" or something like that. |
There were a lot of TypeScript edge cases, where calling functions with certain argument options would result in `any` being expressed as a type, or where the variables/options were not strictly requiring the desired inputs. This adds TypeScript function overloads for all hook edge cases so that all types are correct. This does not change any behavior. This also adds almost complete coverage for types, excepting the cases where `strict` is required, or where a failure is expected, which TypeScript does not currently support. See: microsoft/TypeScript#29394
…ng overloads (#895) * fix: add apollo-composable type overloads + tests There were a lot of TypeScript edge cases, where calling functions with certain argument options would result in `any` being expressed as a type, or where the variables/options were not strictly requiring the desired inputs. This adds TypeScript function overloads for all hook edge cases so that all types are correct. This does not change any behavior. This also adds almost complete coverage for types, excepting the cases where `strict` is required, or where a failure is expected, which TypeScript does not currently support. See: microsoft/TypeScript#29394 * chore: run type tests on prepublish * chore: code style
…ng overloads (#895) * fix: add apollo-composable type overloads + tests There were a lot of TypeScript edge cases, where calling functions with certain argument options would result in `any` being expressed as a type, or where the variables/options were not strictly requiring the desired inputs. This adds TypeScript function overloads for all hook edge cases so that all types are correct. This does not change any behavior. This also adds almost complete coverage for types, excepting the cases where `strict` is required, or where a failure is expected, which TypeScript does not currently support. See: microsoft/TypeScript#29394 * chore: run type tests on prepublish * chore: code style
…ng overloads (#895) * fix: add apollo-composable type overloads + tests There were a lot of TypeScript edge cases, where calling functions with certain argument options would result in `any` being expressed as a type, or where the variables/options were not strictly requiring the desired inputs. This adds TypeScript function overloads for all hook edge cases so that all types are correct. This does not change any behavior. This also adds almost complete coverage for types, excepting the cases where `strict` is required, or where a failure is expected, which TypeScript does not currently support. See: microsoft/TypeScript#29394 * chore: run type tests on prepublish * chore: code style
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'ssuppress_comment
feature.Alternatively, if you want to maintain this behavior, consider creating a
@ts-expect-error
.The text was updated successfully, but these errors were encountered: