Comments (18)
from ember-fetch.
from ember-fetch.
Ugh. I was hoping that fetch
would be an actual npm package, but it's whatwg-fetch
, which isn't even a little bit better than ember-fetch
. I agree that the best option here is exporting from ember-fetch
instead, since the real npm fetch package is something totally different.
Your alternative does bring up an interesting point I'd like to think about in other packages as makes sense: if there's a good reason to, we can presumably teach people how to update the tsconfig.json
as part of the addon installation process. That should certainly be a last-resort option, though.
from ember-fetch.
I was actually curious about the (most) correct path forward myself and thought it might be worth asking @DanielRosenwasser to chime in :)
warning and type defs are below for quick reference
A default export can only be used in an ECMAScript-style module.
export = fetch;
declare namespace fetch {
export default function fetch(input: RequestInfo, init?: RequestInit): Promise<Response>;
}
This is how we import it in our ember applications
import fetch from 'fetch';
from ember-fetch.
A default export can only be used in an ECMAScript-style module.
Right now by default, TypeScript assumes the mapping between ES modules and CJS modules to be 1:1 (the namespace record and the imported object are treated the same). To get around that, you can use --allowSyntheticDefaultImports
.
You can work around this with an explicit path mapping in tsconfig.json, but it's not conventional.
An alternative idea is to add
"fetch": "ember-cli/ember-fetch"
which will get the current state of ember-fetch
from this GitHub repo as a dependency
from ember-fetch.
@DanielRosenwasser thanks for the detailed reply! Reading this it would appear the synthetic option is most appropriate. Any downside to using this option generally speaking?
from ember-fetch.
@chriskrycho @dwickern I just upgraded to typescript v2.6 and this doesn't seem like an issue (anymore?). Here is a repo you can build to confirm it works/ or doesn't for reference
https://github.com/toranb/ember-redux-yelp/commits/branches/seamlessAndTypeScript
Is anyone else having issues w/ TypeScript v2.4/2.5 or 2.6 ?
from ember-fetch.
Still have the same issue with ts2.6 without using a parallel to your solution above, vis-a-viz an ambient module declaration @toranb
from ember-fetch.
We seem to still have this issue with typescript 2.6.2.
from ember-fetch.
I worked around it long since by doing "fetch": ["node_modules/ember-fetch/index.d.ts"],
in my tsconfig.json
, so at present that's the thing to do.
I don't agree with @toranb that the synthetic option is the most appropriate. I think it's actually more correct to have the export and import behave correctly at the package level, and then have the types map to that.
from ember-fetch.
I worked around it by including the types in my own code, but It should probably "just work" when including the package.
from ember-fetch.
I still kind of think that adding a package.json
devDependency of
"fetch": "ember-cli/ember-fetch"
might be the easiest thing.
from ember-fetch.
Just a quick note here - happy to pass the torch to others who legit know TypeScript :)
When I originally wrote these typedefs I was heads down with TypeScript but these days I don't actually use it (yet) and as a result don't know what is best for library/addon authors. If what @chriskrycho is suggesting seems like the best path forward please feel free to make a move without my involvement. I honestly just want to spin up an ember app (with TypeScript) at some point and get no errors when I turn on strict mode (using libraries like ember-fetch)
from ember-fetch.
Believe this issue should be solved now that TS support has been added
from ember-fetch.
I believe @xg-wang βs PR has been merged but not released. So not sure that it has been βaddedβ. I still had this issue this week, Friday, running the latest released version of ember-fetch.
from ember-fetch.
from ember-fetch.
Sorry ember-fetch test is passing, but submitting to npm blocked by typed-ember/ember-cli-typescript#566, open PR DefinitelyTyped/DefinitelyTyped#33518
from ember-fetch.
Always a nice feeling to get rid of workarounds :)
from ember-fetch.
Related Issues (20)
- Version 6.7.2 onwards seems not to transpile to es5 (Caused IE11 Blank screen, with no console errors) HOT 2
- Could not find module `fetch` imported from `prog/instance-initializers/setup-fetch` HOT 2
- Operation outputFileSync is not allowed to use HOT 15
- Where are all the response headers? HOT 2
- Inconsistent Headers objects with preferNative HOT 1
- fetch is not defined - maybe your browser targets are not covering everything you need HOT 31
- v8.0.3 contains `yarn-error.log` file
- Ember 3.27+ issues deprecation for accessing `window.Ember` HOT 1
- Could not find module `rsvp` imported from `fetch` HOT 6
- Version 8.1.0 not released to NPM? HOT 1
- Migration from jquery.ajax $.ajaxSettings.traditional = true. How remove [] from params
- Dropping Node 10, older versions of Ember
- Archive this repo? HOT 16
- Deprecation warning for assign() from ember/polyfills
- Failed to execute 'fetch' on 'Window': Failed to read the 'signal' property from 'RequestInit': Failed to convert value to 'AbortSignal'.
- ember-polyfills.deprecate-assign deprication in Ember 4.4
- ember-fetch `input` type parameter is incorrect
- Upgrade package "node-fetch" to fix
- `Error: cannot find module rsvp imported from fetch`: Ember 4.12 + embroider-optimized scenario HOT 1
- Maintenance, V2, modern `fetch`, etc
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 ember-fetch.