Skip to content
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

Unexpected errors do not error #13

Open
OliverJAsh opened this issue Feb 11, 2020 · 6 comments
Open

Unexpected errors do not error #13

OliverJAsh opened this issue Feb 11, 2020 · 6 comments

Comments

@OliverJAsh
Copy link

Hi, thanks for your work on this project!

If my tests have an unexpected error, e.g.

const add = (a: number, b: number): number => a + b;

add(1);

… then ESLint will return no errors.

The TSLint variant inside dtslint did not have this problem.

@jquense
Copy link
Member

jquense commented Feb 11, 2020

Hey thanks for trying this out. The plugin here isn't meant as a drop in replacement for dtslint as a tool. In particular, eslint doesn't do general type checking for typescript, linting is a layer on top of that. The expectation is you'd still do your normal typechecking with the typescript compiler. Lint rules are sugar on top of that.

In fact tho this what dtslint does, it runs tsc --noEmit against your code as well as tslint. This project is a bit more scoped, providing only the special test-specific lint rule to read and check specific comments.

@OliverJAsh
Copy link
Author

The expectation is you'd still do your normal typechecking with the typescript compiler

But if we do that, tsc will fail due to expected errors, which we don't want it to do. 🤔 We only want it to fail due to unexpected errors.

@jquense
Copy link
Member

jquense commented Feb 11, 2020

fair point. There isn't much we can do tho as an eslint plugin, You'd need a typescript plugin perhaps? Our workflow for tests is that we don't explicitly typecheck them, beyond normal editor support. For test related things that we want to test/make assertions on, we use the $Expect comments. Beyond that tho, running tsc on test code doesn't offer much from a testing perspective (in terms of failing tests via CI, it obviously has DX value).

@OliverJAsh
Copy link
Author

running tsc on test code doesn't offer much from a testing perspective

My worry is that if we don't type check the tests, then when the source code changes, there might be new (unexpected) type errors in the tests. In that case, the tests wouldn't fail during CI, so no-one would notice unless they opened the tests in their editor!

@OliverJAsh
Copy link
Author

Would it not be possible for the lint rule to throw a linting error if the file contains errors which are not marked as expected? This is what the TSLint rule appears to be doing.

@OliverJAsh
Copy link
Author

FWIW this version works as I would expect: https://github.com/ibezkrovnyi/eslint-plugin-expect-type

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

No branches or pull requests

2 participants