Comments (21)
If dart already knows typings information, it would be better if it could itself automatically generate the
.d.ts
. That way, the typings shouldn’t get out of sync and require the community to manually update them.
Dart's notion of what the types are doesn't correspond cleanly to TypeScript's, especially since Dart Sass has to do some dirty tricks outside of Dart's type system to generate the right JavaScript API. Also, the typings already need to stay in sync between Dart Sass and Node Sass, so auto-generating them wouldn't provide much advantage.
from dart-sass.
@xzyfer Does node-sass have these that we can adapt?
from dart-sass.
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/node-sass/node-sass.d.ts ?
from dart-sass.
I'm not intimately familiar with how JS type declarations work. Is this something we should ship with the npm package? Does it need to be declared somehow?
from dart-sass.
@nex3 So if you have exact same public API as node-sass
, we can re-use node-sass.d.ts
and perhaps publish as dart-sass.d.ts
on DefiniteivelyTyped
, which seems the most popular repository for these files.
from dart-sass.
@nex3 Sass types in node-sass are defined in https://github.com/sass/node-sass/tree/master/src/sass_types.
Having them in C/C++ actually causes a decent amount of pain for distributing custom functions. Custom function packages (like eyeglass) end up with an awkward dependency on node-sass.
There is some scattered discussion on what to do about Sass types moving forward. We're currently leaning towards defining Sass types as JavaScript prototypes (or ES6 classes), distributed in a separate package.
The node-sass binding layer to LibSass will handle turning LibSass types into v8 objects. This way custom functions will only deal with JavaScript objects.
from dart-sass.
For the folks who wonder how can we use node-sass
typings with sass
package...
- Install the
node-sass
typings :npm install --save-dev @types/node-sass
- Update the TypeScript compiler options (i.e. edit the
tsconfig.json
file):
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"sass": ["node_modules/@types/node-sass"]
}
}
}
- And voilà!
from dart-sass.
@cedx is step 2 actually required for most people? Modern TypeScript these days automatically looks in node_modules/@types
for typings.
from dart-sass.
If dart already knows typings information, it would be better if it could itself automatically generate the .d.ts
. That way, the typings shouldn’t get out of sync and require the community to manually update them.
from dart-sass.
@binki Yeah, step 2 is required because without it, the TypeScript compiler will look for folder node_modules/@types/sass
(and the package @types/sass
does not exists).
from dart-sass.
@cedx one option is yes to have it in the @types/folder (usually the easiest way)
However, with typescript I believe 2.3+ will pull it in from where you specify from the package.json as well. Thus editors that use typescript definition files would also be able to find them this way. VS Code, JetBrains, even Vim with the youcompleteme
plugin can see these. Those are just the editors I tested off the cuff (and this is one of the big reasons to have them, honestly. The other being its much easier as a library user to grok what is happening and make sense of the API)
Here's a link to the typescript documentation on it
If the dart types were included in this repo (I couldn't find them) I think a good faith effort could be made to convert them until we figure out a better way. It can't be that far off.
from dart-sass.
Again, Dart's notion of types are substantially divorced from anything TypeScript could understand. I think the best way to handle this for now would be to have a build step copy https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node-sass into the generated npm package.
from dart-sass.
@nex3 I completely understand.
I think the real thing here, is since we're doing it by hand anyway, is that having the Dart Types gives us a basis to go off of, with some trial and error involved, rather than guess work. I could probably reason about enough to get something put together with those types, but I don't know Dart to be able to glean it from source code. Where as the type definitions, however ever far off they may be, would at least consolidate knowledge into once place where I can simply look something up if i'm unsure and do my best to map it.
Unless you are suggesting that the node-sass API directly maps the dart-sass API?
from dart-sass.
Unless you are suggesting that the node-sass API directly maps the dart-sass API?
That's right. Both JS APIs are identical.
from dart-sass.
We shouldn't use type from node-sass.
- node-sass is deprecated.
So there are no new features come to node-sass.
node-sass type is considered outdated. - node-sass don't have some option that dart-sass has. e.g.
fiber
option.
So type isn't compatible.
from dart-sass.
FYI: @types/sass seems abandoned. I have a problem with DefinitelyTyped/DefinitelyTyped#32091 for year.
from dart-sass.
Just a quick one, in regards to sass/sass#3067, as fibers seems to be dead now (ref), do I:
- take the type declaration from the DefinitelyTyped repo and add it straight into my file - this one
- ignore the property as the error can be bypassed with a
@ts-ignore
until the new (more preferred) API entry point emerges - which I believe doesn't use fibers??? - sass/sass#3056 - add a general property with an
any
type - ask sass to have their npm package depend on the
@types/fibers
and have the/// <reference ...
from dart-sass.
If we were going to continue using Fibers, I think the principled answer would be option 4. However, since it's dying and doesn't seem likely to be revived, I think option 3 is probably the path of least resistance.
from dart-sass.
from dart-sass.
Hey @nex3, I noticed that v1.45.0-rc.1 has now been released.
Are you planning on including a .d.ts
with the npm package? This way we/I can drop the dev dependency on the already outdated/unmanaged @types/sass
package. I only ask because I can see you have already done the work over at: sass/sass/js-api-doc
from dart-sass.
I'll see if I can throw something together using the type definitions from the language repo.
from dart-sass.
Related Issues (20)
- Doesn't run on alpine linux HOT 6
- Using `math.random()` in css module leads to a wrongly generated class names HOT 1
- Bad state error when using `meta.apply` and compile with `render` HOT 2
- Unable to use meta.get-mixin to pass mixin as a value to another mixin, then use it in its content. HOT 3
- FileSpan is not defined when using @warn with a custom logger. HOT 1
- Anyway to wrap @use like we can with @import HOT 3
- Q&A: How can i fix waring import sass from 'sass'` is deprecated HOT 4
- Q&A: How to prevent color names being transformed to hex values HOT 2
- Dependency URLs with a `file` schema fail to resolve
- Standalone sass compiler: Can't find stylesheet to import HOT 1
- [feature request] Official Python bindings to replace `libsass-python` HOT 3
- box-shadow property not respecting strict unary operator with 0
- linux-musl 1.71.0 release builds are broken
- ESM export of `NodePackageImporter` is missing.
- Node package importer requires an entryPointDirectory in ESM HOT 1
- Deprecation message replaces underscores with hyphens HOT 2
- NodePackageImporter support for subpaths entry points without extensions HOT 8
- Build Errors with Latest Sass Version in GitHub Actions CI/CD Pipeline HOT 7
- Doesnt execute custom functions in renderSync HOT 1
- Node Package Importer can't find ESM entry point if args are provided HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dart-sass.