4 ms·
It strips type info and runs it as Javascript, though. There's no native typescript runtime, AFAIK (it doesn't enforce types at runtime, only at build time)
by abdusco 4y ago
It strips type info and runs it as Javascript, though.
There's no native typescript runtime, AFAIK (it doesn't enforce types at runtime, only at build time)
- djxfade 4y agoThere is no such thing as a TypeScript runtime. TypeScript has always been a static typechecker
- rtpg 4y agoPeople say this all the time. What does “enforced type system” mean to you? To my knowledge there is no language with a system that adds type checks (except in the case of checking a cast inside of a nominal type system). Casts are such a tiny slice of code, and you can choose to not use them! It adds tedium, but none that would be missing in other languages.
- croes 4y agoYou do realize deno is based on the V8 JavaScript Engine and there isn't such thing as a typescript runtime even by Microsoft the developers of typescript? https://en.wikipedia.org/wiki/TypeScript https://en.wikipedia.org/wiki/TypeScript
- norman784 4y agoDeno used to run the type checker with the `run` command, but now you need to pass a flag to run the type checker.
- christophilus 4y agoAnd that’s a good decision. It lets you choose fast start times and run your type checker in your editor or a separate console, which is what I do in all of my Node applications.
- nisegami 4y agoSounds like that could be resolved with a simple alias in your shell?
- brundolf 4y agoThis is different from what the GP is asking about, though
- __alexs 4y agoMost languages intentionally avoid checking types at runtime except in specific situations where it's required (e.g. explicit typeof checks.) You do not want run time type checking on every variable access.
- skoskie 4y agoPHP has entered the chat.
- egeozcan 4y agoYou can always use one of the million different runtime type-checking libraries at IO boundaries.
- norman784 4y agoIm not sure why are you down voted, because your statement isn’t wrong, I’m not sure of Deno internals, but what GP said is also true, AFAIK is similar to run your TS app with ts-node but without the need to add a dependency, so it means that you just execute `deno run index.ts` and it worke, I’m not 100% sure but I think is also works with tsx/jsx files.
- lucideer 4y agoWhile the comment is technically accurate, it's: (a) worded as a contradiction to the parent comment but isn't (it just talks about something unrelated - runtime typechecks). Deno does run typescript code out of the box, typechecks aside. (b) the technical accuracy isn't particularly significant/relevant since in practice Deno has a simple switch to check types on run (though I'm not sure why you would want to do that outside of a development environment: Typescript is a static tool & doesn't have any dynamic capabilities that would change results based on runtime environment).
- MarquesMa 4y ago> It strips type info and runs it as Javascript, though. There's no native typescript runtime, AFAIK (it doesn't enforce types at runtime, only at build time) Java strips type info and runs it as JVM byte codes. There's no native Java runtime, AFAIK(it doesn't enforce types at runtime, only at build time). What's the problem?
- deleted 4y ago[deleted]
- eyelidlessness 4y agoYou probably don’t want that throughout your entire codebase. It’s a lot of overhead. Where you do want it (at API/user input/network etc boundaries), you can use something like Zod[1] or similar to define your type guards and then infer the static types from there. 1: https://github.com/colinhacks/zod https://github.com/colinhacks/zod
- _greim_ 4y ago> There's no native typescript runtime. A proposal was actually floated recently to grandfather in TypeScript-like annotations[1]. It would be ignored by the runtime and treated purely as a comment, and would be optional. This is what native runtime support for TypeScript would look like. Not sure if it will ever gain official support in the language though. > it doesn't enforce types at runtime, only at build time Runtime type "enforcement" is just your program breaking, for example "undefined is not a function". Well, I guess it isn't so simple, because JS does a lot of implicit type translation behind the scenes, like helpfully converting "123" to 123. It would be possible to "enforce" types at runtime by turning off that language feature in certain situations, but I don't think it will happen, for back-compat reasons. [1] https://github.com/tc39/proposal-type-annotations https://github.com/tc39/proposal-type-annotations