-
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
Don't fail on ts compile when running a script ? #3321
Comments
—no-type-check ? |
@ry I would advise against that... there is Throwing out the whole type checking is like saying to the V8 runtime to ignore syntax errors... 😢 |
@ry That would fix my current use case, but I would also suggest an option to remove checks entirely (if the tsc emits valid js, that's what is run.) I can imagine using third party libs that don't pass the compiler 100% (maybe deno's typescript is a different version, idk). If I'm scripting I don't want my entire script to break because of a compiler error. @kitsonk A V8 runtime with no errors... it would start assuming what you meant. Would that be bad? idk :) |
Is there a corresponding tsc option? I'd rather not invent names @kitsonk You might want this for starting up quickly. |
@ry there are As for the option name, people are asking for |
I agree, there is the concept of transpile only. There is a slightly loose version of the compiler that is the no default lib check. I guess if there ends up being a transpile only on the compiler, we would want to support it, but we would want to support it through tsconfig if it becomes a compiler feature. |
Wesley (TypeScript core team) pointed out that we can use |
ts.transpile might be useful for the REPL too /cc @kevinkassimo |
yeah, still a bit more complicated, because you only want to run the changes between the last transpile (REPL command) and the current, but it could be a step in the right direction. |
There is also a TypeScript preset for Babel that I believe just erases the types without compiling (as opposed to tsc compiling and ignoring errors, as I understand it) which may be a much faster approach in getting JS out of known good TS (one possible use case) or even getting a try-at-your-own-risk JS out of known bad TS (for development, debugging, testing, quick hacks).
From https://devblogs.microsoft.com/typescript/typescript-and-babel-7/ There are actually two Babel preset and plugin, one is using the other:
They don’t have the ability to do any type checking so I guess they should have a potential to be much faster and simpler. Maybe a type-erasing fast path based on type erasing babel-style instead od using internal tsc would be a possible optimization for the future dor things like std modules etc.? |
@rsp this is interesting, I had another idea as well. TS can emit declaration files alongside JS, which we could cache as well along with compiled output and sourcemap. Then when you compile a script and you find a dependency that has declarations file in cache you substitute source file with declaration file (just like we do using |
@ry @kitsonk is it possible to optimize the repl in a way that vscode is working? It uses tsserver (which is tsc working in a different mode optimized for interactive work) and it can recompile on every keystroke, of course recompiling only what’s needed because of time constrains. Anders Hejlsberg explains it in this part of his video on modern compilers very well. Maybe a repl can use a similar approach? |
@bartlomieju Interesting. Some time ago I was also thinking about services like deno.land/x serving (or redirecting to) a .js/.d.ts combo in addition to .ts source of files that are compiled and cached on the server (github, cdn, whatever). Let’s say that a cli switch like —prebuilt or something adds a special header or query param in http requests and if that header/param is recognized by the server it returns a compiled version of js plus type definitions. If the header/param is not recognized then you get a normal ts file and nothing changes, but if it is supported then it could speed up loading libraries even more than erasing types or compiler optimization. Update: I mean it with addition to what you are describing here, not instead of. |
This should be closed due to #6456. For example: $ cat foo.ts
export function f(x: string): number { return x; }
$ cat bar.js
import { f } from "./foo.ts";
console.log(f("test"));
$ deno run bar.js
Check file:///home/scott/tmp/bar.js
error: TS2322 [ERROR]: Type 'string' is not assignable to type 'number'.
export function f(x: string): number { return x; }
~~~~~~~~~
at file:///home/scott/tmp/foo.ts:1:40
$ deno run --no-check bar.js
test |
Can this flag be used when embedding deno? |
|
Thank you, @kitsonk. I guess all I need then is to pull the latest from upstream in hirosystems/clarinet#282 since it appears as they're using an older version of deno currently. |
If I want to run my script via "deno run foo.js" and foo.js depends on a ts library that emits perfectly working js code but has a compiler error, deno shouldn't fail prematurely during the compile step and instead run my script with the emitted js file.
Typescript always emits code by default and you have to override that behavior with noEmitOnError. Shouldn't deno allow you to keep running your scripts?
The text was updated successfully, but these errors were encountered: