-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Not Type Checking TypeScript #5436
Comments
I understand that skipping type checking is desirable or necessary in some cases, but doesn't a One of the goals of Deno is to promote a large standard library written in TypeScript and I would personally find it weird that by default, programs could make an incorrect use of it. Having different opt-in/opt-out policies for different deno commands would be even more confusing IMO. |
I am suggesting effectively this, just a question of it being |
What are the arguments for I think it would be confusing to claim to have first class TS support and not type check by default. |
Testing is one use case where type checking at "authoring time" instead of later can get in the way; prototyping is another. Not having a way to opt out of it is a significant limitation. |
Again, I was originally against this idea. But many developers use IDEs to develop JavaScript or TypeScript. Those editors enforce types as you edit the code. Therefore Deno type checking is effectively redundant. Type checking will always have overhead to starting up Deno. Currently it is about 10x just using JavaScript, even if it is just 1 TypeScript file. If 90% of the time you invoke Deno, you already have a safety net of an editor, then 90% of the time you are "wasting time". Over the long term it could be argued that erodes adoption of TypeScript. Part of the reason many of us got into JavaScript in the first place was it was easy to make changes rapidly, versus the old way of having to wait for a compiler build. |
That doesn't mean deno should be unsafe by default. Aliasing |
Sure, but that doesn't catch all errors necessarily. If I edit a type in a large project it might lead to errors in a different file that is not open and I might not see this error. This might lead to errors and negates the point of TS. I am aware of the overhead and that is a problem. Let's see if #5432 helps. If it does, that might be enough |
Also, if a user is sure that the IDE checking is enough, they could still use the Doing it the other way would lead to users oblivious that no checking occurs. |
Edit I think here Why does the compile and type checking need to be synchronously? Can't it emit the JS immediately and run it. Then do type checking delayedly in separate thread? I think the "no-type-check" option should be an option. Maybe even recommended option e.g.
If it were named If you run without the production flag it could include development time improvements: type checking in separate thread, emit and run as fast as possible so you can see changes immediately, hot module reloading etc. Note Why --production and not --development? Think it like this, how often do you run the development mode vs production mode from cli? Answer is that default should be development mode because we developers who use the cli do that all the time. In development mode the type checking is critical but in production mode you probably want just speed, and production mode is ran less often: thus |
I like the idea of an option for speed hacks, but it has to be clear to the user what is dropped for speed. If they don't know that type-checking is dropped, they might use it always and be frustrated when errors aren't caught. And I know it was just an example, but |
Basically I am just saying what the majority before have said in this thread. I think a What is the problem for the user to just add |
This issue already exists with different |
TS 3.9 introduces @ts-expect-error directives which are designed to solve exactly this problem: https://devblogs.microsoft.com/typescript/announcing-typescript-3-9-beta/#ts-expect-error-comments |
Worth noting: |
Blocked by swc-project/swc#769
@kitsonk would there be any difference in compiled source code depending if type checking is on/off? Once "no type check" option is working it'd err to always use the same method for transpiling TS to JS (ie. SWC). TSC would only be used to perform the type check, but without emit step. |
There should be no type directed emits, true... but I am just thinking about transitory dependencies, where if we aren't careful, we could either not detect errors. Right now, type checking is the barrier to if something populates that cache, it won't be with this option. I think we just need to think about it. |
swc-project/swc#769 is now resolved. |
With #5029 landed this issue is now feasible. Unfortunately we'd still need to use TS compiler worker instead of SWC, but I guess it should be a net gain anyway. @kitsonk how do we tackle this problem, could we just use |
@bartlomieju yup... the runtime compiler API for transpileOnly should be close... important thing is that there are |
I've started work on this and have it working in a branch, except ran into a major challenge... With TypeScript constructs like: export { AnInterface } from "mod.ts"; Because the transpiler isn't looking at any sort of type information, it doesn't know that export type { AnInterface } from "mod.ts"; |
I'm sad that the opt-out Also as already mentioned by other people, perfectly fine JavaScript with wrong types won't run anymore by default. People here say this is being "safe", but this has nothing to do with safety. Safety is guaranteed by the sandbox and permission flags. Not running perfectly fine code by default because of what is essentially "incorrect comments" is just wrong. |
Type checking TypeScript and transforming it to JavaScript will always be slower than just transforming to JavaScript. We have talked around the issue before in #3321 and #4323 but it makes sense to be clear about the need for this feature. It makes sense though to allow a user of Deno to be able to opt in or out of full type checking of TypeScript. Especially when other tools are in place (like an intelligent IDE) or there is fail fast prototyping going on, Deno forcing type checking only impedes the use of TypeScript, which is a sad thing.
We should have a "flaggable" mode where TypeScript files are not typed checked, but simply transformed/type stripped.
We currently use swc for
deno doc
anddeno fmt
. We should consider using swc to do the parsing and transform.We should also figure out if type checking is on or off by default. There are arguments both ways. I personally was of the opinion that it should be on by default, but recent conversations have me leaning towards off by default, (though maybe on by default with
deno test
).Another consideration is how we handle the cache when switching between modes, and ensure invalidation of the cache occurs in a way that meets expectations.
There is work in progress to move dependency analysis out of the compiler isolate into Rust (see #5029) which is really a pre-req before we can really land anything related to this.
The text was updated successfully, but these errors were encountered: