4 ms·
The TypeScript portion is a little bit wrong. Return position void in TypeScript means the value is unobserved by the caller, not that it's undefined. It's subt
by spoiler 2y ago
The TypeScript portion is a little bit wrong. Return position void in TypeScript means the value is unobserved by the caller, not that it's undefined. It's subtly different.
- langcss 2y agoTypescript also differentiates between checking and compiling as two different steps. So you could return something from a void function and use it and that will compile to JS and work but only the compile time type check would fail. Highlighting that of course TS has no runtime checks of types.
- spoiler 2y agoYes, that's true of TypeScript in general. Code that fails type checking still gets emitted as JS. It's a bit annoying, but there's good reason for it. However, it can be controlled with compilerOptions.noEmitOnError (can be passed as a flag too). https://www.typescriptlang.org/tsconfig/#noEmitOnError https://www.typescriptlang.org/tsconfig/#noEmitOnError That being said, if using something like SWC or wrappers that's less useful, since they don't type check. TypeScript is great, but setting up projects that use it often come with some tradeoff (but I still think TS is worth it)