Earlier quoted context omitted.
Are they not using attributes, which start with a #? I thought PHP had C style // comments.
They are attributes. PHP does also allow # as a comment character in addition to // style comments and I assume that's where the poster got confused.
TS to JSDoc Conversion
71–80 of 163 posts
Re: TS to JSDoc Conversion
#72It's immediately clear from the very first few lines of the PR that they're sacrificing safety for this. Before: import { Node } from 'acorn'; import * as code_red from 'code-red'; export const parse = (source: string): Node => code_red.parse(source, { sourceType: 'module', ecmaVersion: 13, locations: true }); After: import * as code_red from 'code-red'; /** * @param {string} source * @returns {any} */ export const p…
You are making judgements based on a draft PR. There is a ton of work still to do.
EDIT: It'd be a great outcome in the end if this conversion spurs DX improvements in Node/TS.
Re: TS to JSDoc Conversion
#73The developers providing everyone with free tools are or course welcome to write those tools in whatever languages they want. But to me, the comment definitions are longer to type and more difficult to parse than inline type definitions. I would much rather use one of the quick TS compilers that don't actually type check when I want to make and test a small change to my source code. But to each their own!
Re: TS to JSDoc Conversion
#74For anyone who is still confused - they're still gonna be using TypeScript in that they will have a tsconfig.json, `allowJS: true, checkJS: true` but they are just writing the files in JS with JSDoc type annotations, they'll still have `.d.ts` files to allow TS developers to use it without issues. Is it contrarian - yes - is it insane - no, not really. Edit: the motivation seems to be to simplify processes - running…
TS can generate d.ts files from JS files that use JSDoc
Re: TS to JSDoc Conversion
#75If I remember right, symfony (php framework) has comments that affect how the code runs which as far as I’m concerned means they’re not comments at all but actually code masquerading as comments. Reading about JSDoc gives me the same uneasy feeling, even if it’s not quite the same thing. Edit: Here’s one example, you can define your routes in symfony using comments. Not only that, but it’s actually the officially rec…
What you're thinking of in PHP is not a comment. It's called an Attribute, is built into PHP itself, and while it does use a comment-syntax, it's the old style that is largely unused today ("#" at the start of a line). https://www.php.net/manual/en/language.attributes.overview.p...
JSDoc isn't similar at all, unless you build a compiler that does different things based on your JSDocs.
Re: TS to JSDoc Conversion
#76Why would anyone do this?
> As a Svelte compiler developer, debugging without a build step greatly simplifies compiler development. Previously, debugging was complicated by the fact that we had to debug using the build step. In addition, using JSDoc does not affect compiler’s development safety because the type is almost equivalent to TS. > Of course, Svelte developers (not compiler developers) will still be provided type definition files as…
Re: TS to JSDoc Conversion
#77A bit off-topic (sorry): Is anyone using Svelte in production without SvelteKit? Hows Svelte documentation as of late?
Re: TS to JSDoc Conversion
#78It's immediately clear from the very first few lines of the PR that they're sacrificing safety for this. Before: import { Node } from 'acorn'; import * as code_red from 'code-red'; export const parse = (source: string): Node => code_red.parse(source, { sourceType: 'module', ecmaVersion: 13, locations: true }); After: import * as code_red from 'code-red'; /** * @param {string} source * @returns {any} */ export const p…
You are making judgements based on a draft PR. There is a ton of work still to do.
What's the estimated ROI?
Re: TS to JSDoc Conversion
#79Earlier quoted context omitted.
ts-node [1]: am i a joke to you? [1] https://www.npmjs.com/package/ts-node
I’ve generally found tsx to be better/less hassle than ts-node https://github.com/esbuild-kit/tsx
I gave tsx a test and found it has a 3x slower boot than my favorite one, tsm[0] (and this is using the native binary at "./node_modules/bin/tsx").
Unfortunately, tsm has much lower download numbers compared to tsx, so I can already see me jumping ship to it due to traction.
I usually install tsm locally with "--save-dev" and use "node -r tsm --enable-source-maps .ts" to run what I want. Here on a M1 Pro 32GB the difference between both is 0.17s for tsx and 0.06s for tsm.
I urge anyone that haven't tried yet to give tsm a chance. It works great with PM2 if you create a file like "server.pm2.js" and just add at the top of it "require('tsm')" followed by "require('server.ts')".
Re: TS to JSDoc Conversion
#80If I remember right, symfony (php framework) has comments that affect how the code runs which as far as I’m concerned means they’re not comments at all but actually code masquerading as comments. Reading about JSDoc gives me the same uneasy feeling, even if it’s not quite the same thing. Edit: Here’s one example, you can define your routes in symfony using comments. Not only that, but it’s actually the officially rec…
Docblock comments can also be inspected with reflection [3] but have a much looser syntax, so it was up to you to parse them. Where as you can create a new instance of an attribute directly from the reflection object [4]
In your example Symfony uses it to build up the list of HTTP routes by looking through all your controllers for #[Route] attributes. Generally that's done once and then cached, at least in production.
Personally I try to avoid using them, but they're definitely not comments. More like metadata you can attach to classes/methods/properties/parameters then use however you want.
[1]: https://www.php.net/manual/en/language.attributes.syntax.php
[2]: https://www.php.net/manual/en/reflectionclass.getattributes....
[3]: https://www.php.net/manual/en/reflectionclass.getdoccomment....
[4]: https://www.php.net/manual/en/reflectionattribute.newinstanc...