It'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…
We're using an automated tool to do the gross conversion, then combing through fixing the issues. There's a reason the PR's a draft, dammit! :lol: Don't worry, _no_ type-safety will be lost, internally or externally.
TS to JSDoc Conversion
121–130 of 163 posts
Re: TS to JSDoc Conversion
#122Earlier quoted context omitted.
> It's also a really contrarian viewpoint about typescript which is really popular. I really, really don't get the controversy here. JSDoc _is_ TypeScript, just with a syntax that's valid JavaScript (on account of it living in comments). This means it doesn't have to be built to run, but still gets all of the typing goodies regular TypeScript does. The end-user code authoring experience is the same or better. > To co…
> "It's regressive to use a fully-JS TypeScript syntax instead of using dozens of tools on top of regular TypeScript to achieve the same outcome" is quite a spicy take. To be fair, "We are so invested in TypeScript we're dropping it!" is an equally astonishing take. It's language I'd expect from Google about any of their projects.
Re: TS to JSDoc Conversion
#123Earlier quoted context omitted.
Digs through some of my Javascript Twitter rants The latest I ran into, `Object.keys(x).length` appears to recalculate length on every call. There doesn't appear to be a fast (and idiomatic) way to get top level object size in Javascript without using a secondary incrementor.
This seems like a very odd example in many ways: 1. How on Earth would you expect a type validation library to assist with this example? 2. Looking at that example, I would expect that of course it would need to do work on every call. That is, Object.keys(x) is a function call that takes an object and returns a newly constructed array. So I'm not exactly sure what you would expect to be optimized here. I guess what y…
Re: TS to JSDoc Conversion
#124Isn't casting with JSDoc impossibly ugly though? The inputs/outputs of a function signature are not the only times a type annotation is needed in TS.
In practice, what I’ve found is that the hassle of adding type assertions even if they’re correct nudges me to write worse code (“to appease the type checker”) in JS/Doc than it does in TypeScript syntax. I don’t think TypeScript syntax makes me feel more relaxed about writing unsafe type assertions, but I’m probably an outlier because I pretty much only do that when I’ve exhausted every other available/known approach.
Re: TS to JSDoc Conversion
#125A bit off-topic (sorry): Is anyone using Svelte in production without SvelteKit? Hows Svelte documentation as of late?
Re: TS to JSDoc Conversion
#126JSDoc and Typescript don't have feature parity: OOP that works across files, generics, inline types, etc.
This is a non-issue in practice — complex types can be expressed in .d.ts files and imported. SvelteKit (not Svelte) has been doing this for a long time and it's fine.
I’d be thrilled to make the concession to a TypeScript flavor of header/implementation file pairs and skip a build step for huge portions of my work. But I spent way too long trying to figure out how to do it and my only remaining hope that it’s even possible is to wait for the “you don’t know?!” replies. (If it’s not clear here, they’d be very very welcome!)
Re: TS to JSDoc Conversion
#127Earlier quoted context omitted.
Is there any reason you wouldn't want to use SvelteKit now that is has reached version 1.0?
The business apps I work on don't benefit from SSR (having to write components that can render server-side is friction without payoff), and I already have a client-side router that supports nesting.
Also in the process of writing an app that has no ssr needs. There are some minor annoyances with SvelteKit and interested in other options.
Re: TS to JSDoc Conversion
#128Earlier quoted context omitted.
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.
You can call it an “attribute” and you can also call it a “comment that affects the code” - they’re both just labels for the same thing. If you don’t want the latter to be a legitimate label (and it is, because I’ve communicated that idea with those words and you’ve understood what I’m referring to immediately) then the solution is to use any other symbol other than those reserved for comments. Imagine if we just had…
Re: TS to JSDoc Conversion
#129Earlier quoted context omitted.
> as I’m concerned means they’re not comments at all Smuggling pragmas in comment has a long and rich history. It’s literally the reason why json does not support comments. > Reading about JSDoc gives me the same uneasy feeling, even if it’s not quite the same thing. It’s not just “not quite the same thing”, it’s entirely unrelated in every way and shape. JSDoc does not affect the runtime behaviour of its code, or ho…
> JSDoc does not affect the runtime behaviour of its code, or how that code interacts with other systems. At the moment. You’ve literally just said yourself that there is a long history of smuggling code into comments. A few years down the line I don’t want to suddenly have the feature added and then have to be on the look out when I’m debugging a codebase for secret code in comments.
Re: TS to JSDoc Conversion
#130I don't care what svelte does, but I've maintained projects with jsdoc types and projects using ts directly and IMO using jsdoc tends to be more of a hassle to maintain, had worse ide guidance and in general felt just more cumbersome. Being able to click through to the implementation in your ide is nice though, but can be solved by the ide.