Earlier quoted context omitted.
Not TypeScript the language, but TypeScript the typechecker program. “Typescript without transpilation” is still perfectly accurate.
Vouched. This is the point of the thing - the typechecking benefits come from running `tsc` on your code (or VSCode will do it for you in the background and show you linter errors if you have typescript installed somewhere it knows about). Incidentally I've been doing my JS projects this way for 2-3 years and I really dig it.
TypeScript Without Transpilation (2021)
31–40 of 46 posts
Re: TypeScript Without Transpilation (2021)
#32Re: TypeScript Without Transpilation (2021)
#33Earlier quoted context omitted.
Vouched. This is the point of the thing - the typechecking benefits come from running `tsc` on your code (or VSCode will do it for you in the background and show you linter errors if you have typescript installed somewhere it knows about). Incidentally I've been doing my JS projects this way for 2-3 years and I really dig it.
I started one side project like this recently and it's been great so far.
Actually since this conversation is going, here's something I just learned this week that somebody might find helpful. I used to consider enums one of the clunky bits, but I just ran across the `keyof` operator:
var modeNames = { FOO: 1, BAR: 2 }
/** @param {keyof modeNames} mode */
export function doThing(mode) {
// the jsdoc type above is equivalent to {'FOO'|'BAR'}
}
Probably old hat to TS people, but since I came at it from the other direction (I'd been using JSDoc for traditional doc-creation reasons before I realized VSCode could use it for linting and type hints) it was news to me.Re: TypeScript Without Transpilation (2021)
#34Sorry for being that guy, but this should probably be called "typechecking without transpilation". What ends up being written is not TypeScript syntax (which does require transpilation to run). JSDoc is awesome for incremental adoption though, I've migrated a few codebases this way without too much pain.
Not TypeScript the language, but TypeScript the typechecker program. “Typescript without transpilation” is still perfectly accurate.
- Type checking
- Transpiling to multiple formats (CJS/ESM, JSX and the like)
- Generating declaration files (.d.ts)
While there are modern alternatives for transpiling, much faster than tsc (esbuild, swc), typechecking and declaration generation are still very slow operations.
Re: TypeScript Without Transpilation (2021)
#35Does anyone know if I have a TypeScript project, is there an automated process to turn it into this format this article describes? Eject for TS, I guess.
Re: TypeScript Without Transpilation (2021)
#36Earlier quoted context omitted.
Could that improve execution performance?
Runtime type checks usually decrease the performance.
Re: TypeScript Without Transpilation (2021)
#37JSDoc comments are definitely not the “best of both worlds,” they are a limited and verbose subset of typing. I would only use them for specific reasons, like I’m in a hostile ecosystem that dogmatically doesn’t want any build steps (like WebGL/WebGPU engines).
When I write them I don’t annotate types though, that’s already done by typescript, and editors like vscode even gives you type hints in a js file if it detects d.ts files in the source.
Re: TypeScript Without Transpilation (2021)
#38Does anyone know if I have a TypeScript project, is there an automated process to turn it into this format this article describes? Eject for TS, I guess.
Re: TypeScript Without Transpilation (2021)
#39I've found a happy medium to be annotating functions etc with JSDoc style comments but keeping interfaces etc. in a .d.ts file. The Typescript compiler is able to import it from a .js file just fine.
/// Top of file usually
/**
* @typedef {import('./typedefs/MyThing')} MyThing
*/
/// Later
/**
* @param {MyThing} x
*/
function(x) {
//
}Re: TypeScript Without Transpilation (2021)
#40Someone here just suggested to import type definition files with JS doc annotations, and that's actually a good idea.