-
Notifications
You must be signed in to change notification settings - Fork 303
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
Using with typescript? #612
Comments
Ah right, so including |
There should be a |
ok, so the actual |
Provided everything is in the same runtime environment, then |
ok thanks, have added the reference and it is all working, although |
hmm right so first problem, so I added the path to the sugar stuff as requested:
This works fine in If there is no quick fix is there a recommended way to make the reference path work fine in projects dependent on the one that includes the path, as the relative paths wont always be correct, and adding a base path or something to a project just for sugar seems overkill. |
Hmm... I'm not sure exactly what you're doing, so it's hard to identify a quick fix. Ideally an app should have one entry point and Sugar should be both required and extended there. This is more or less a hard requirement for using Sugar in extended mode, as modifying the global state is something that only makes sense to do once. If for some reason Sugar needs to be used in multiple places that cannot share a common entry point, then I would argue that it's incorrect to use extended mode because it could potentially affect other areas of your application where you are not intending/expecting the global state to change as by definition you are requiring it further down the chain. |
Thanks for getting back to me, so the scenario I have here is there is a library (not an application, just a module for re-use in other projects), and that uses sugar for things like
So like you say there is one place where it does the whole inclusion and extending for sugar, and it needs the reference path otherwise stuff inside the project just throws errors where there is any sugar methods (i.e sortBy). So anyway the above works in that module, but when I build that module (compile ts and generate d.ts) and publish it, and then go to consume it in some other library/app, as its exported the reference path, it would import that in the consuming app and blows up as the reference is not in the same place. So to simplify |
I'm going to circle back to TypeScript issues soon, I'll have a look at that when I do.... thanks! |
Hi @andrewplummer any news on this? The definitions could use the latest typescript features to be more "typed" |
Yes lots coming on this one. Typescript will be fully supported. |
Hey I have just picked up an older project to do some more work on it and I keep getting errors saying that
assign
andsortBy
etc are not found. To my knowledge you package asugar.d.ts
with the project that should get picked up (and does seem to get resolved) but it doesn't seem to use the extensions defined in there.Can anyone provide a succinct example of using it as a module within the TS world?
I assumed I would just need to do:
Have also tries
import * as Sugar from "sugar"
and done theSugar.extend()
not sure if that is needed per file in a module or just once somewhere in the module, but either way that doesn't seem to satisfy the typescript compiler.My errors look like:
Using Sugar: 2.0.4
Using Typescript: 2.4.2
Also these errors crop up:
The text was updated successfully, but these errors were encountered: