8000 [Proposal] publish a sass-types package with type declarations for the standardized JS API · Issue #4037 · sass/sass · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Proposal] publish a sass-types package with type declarations for the standardized JS API #4037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
stof opened this issue Feb 21, 2025 · 1 comment
Labels
enhancement New feature or request infrastructure Non-spec task or chore

Comments

@stof
Copy link
Contributor
stof commented Feb 21, 2025

This repo contains the source code for type declarations for the JS API, as the JS API is standardized between sass-embedded and sass (and node-sass for the legacy API). those files are then copied in the npm packages being built for sass and sass-embedded, which is how they are consume.
This works fine for projects installing a specific implementation and wanting type checking for using it. However, it is painful to write type declarations for a package compatible with any implementation of the standard JS API. And nowadays, most build tool or bundler plugins handling sass are in that category to allow projects to decide whether they want to use sass or sass-embedded.

For instance, I want to contribute to DefinitelyTyped to provide the type declarations for gulp-sass 6.0 in @types/gulp-sass. The version 5 depends on @types/node-sass to get the type finition of the legacy API (which is already incomplete as it is an old version of the legacy API). this makes my project install @types/node-sass even if I don't use node-sass, but that only a few KB so that's not a big issue. But as sass now ships its type declarations directly in the package, the direct implementation today would require depending on sass instead. If a project uses sass-embedded, this would make the project install both sass and sass-embedded, which would be wasting a lot more space.

It would be great to publish a type-only npm package for the JS API (basically, publishing the js-api-doc folder of this repo, with a different readme file aimed at the package page rather than spec contributors). This way, such plugin loader could depend only on sass-types (or @sass/types even though existing packages don't use a @sass namespace).
This sass-types package would be published with version in sync with sass and sass-embedded for simplicity. Thanks to the way they are managed, functions exported from sass would satisfy the types defined in sass-types and so would be usable with a plugin using sass-types (except for the NodePackageImporter type that relies on a unique symbol hack to distinguish the exact class being used, but this is on purpose actually: someone using sass-embedded must use the NodePackageImporter of sass-embedded and not the one of sass, but that's not the kind of things you would need for the code of a generic plugin anyway).

this approach is what babel does with @babel/types for instance, having a type-only package exporting types that are depended on by the various babel plugins. It is also done by @jest/types, @typescript-eslint/types or undici-types (and probably others that I don't have in the dependencies of my work project where I found those examples)

What do you think about that ?

@nex3
Copy link
Contributor
nex3 commented Feb 21, 2025

This seems reasonable to me. We'd have to do a fair amount of work to get the release infrastructure working for it, though.

@nex3 nex3 added enhancement New feature or request infrastructure Non-spec task or chore labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request infrastructure Non-spec task or chore
Projects
None yet
Development

No branches or pull requests

2 participants
0