[Proposal] publish a sass-types package with type declarations for the standardized JS API · Issue #4037 · sass/sass · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 ?
The text was updated successfully, but these errors were encountered:
This repo contains the source code for type declarations for the JS API, as the JS API is standardized between
sass-embedded
andsass
(andnode-sass
for the legacy API). those files are then copied in the npm packages being built forsass
andsass-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
orsass-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 onsass
instead. If a project usessass-embedded
, this would make the project install bothsass
andsass-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 onsass-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 withsass
andsass-embedded
for simplicity. Thanks to the way they are managed, functions exported fromsass
would satisfy the types defined insass-types
and so would be usable with a plugin usingsass-types
(except for theNodePackageImporter
type that relies on a unique symbol hack to distinguish the exact class being used, but this is on purpose actually: someone usingsass-embedded
must use theNodePackageImporter
ofsass-embedded
and not the one ofsass
, 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
orundici-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 ?
The text was updated successfully, but these errors were encountered: