Skip to content
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

TypeScript support #136

Merged
merged 3 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ module.exports = {
'no-console': ["error", { allow: ['warn'] }]
},
overrides: [
// TypeScript files
{
files: ['addon/**/*.ts'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
'no-undef': 'off',
'no-unused-var': 'off'
}
},
// node files
{
files: [
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ Available imports:
import fetch, { Headers, Request, Response, AbortController } from 'fetch';
```

### Use with TypeScript
To use `ember-fetch` with TypeScript or enable editor's type support, add `"fetch": "ember-cli/ember-fetch"` to your app's `devDependencies`.
This will get the current state of `ember-fetch` from this GitHub repo as a dependency.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we want to advise that people do this, since they'll end up tracking the master branch rather than SemVer versioned releases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to document tsconfig.json only.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please clarify. This pertains to package.json, not tsconfig.json

add "fetch": "ember-cli/ember-fetch" to your app's devDependencies.
This will get the current state of ember-fetch from this GitHub repo as a dependency.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the "fetch": "ember-cli/ember-fetch" instruction and only left a tsconfig example


You can also add `"fetch": ["node_modules/ember-fetch"]` to your `tsconfig.json`.
xg-wang marked this conversation as resolved.
Show resolved Hide resolved

### Use with Ember Data
To have Ember Data utilize `fetch` instead of jQuery.ajax to make calls to your backend, extend your project's `application` adapter with the `adapter-fetch` mixin.

Expand Down
11 changes: 0 additions & 11 deletions addon/ajax.js

This file was deleted.

14 changes: 14 additions & 0 deletions addon/ajax.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import fetch from 'fetch';

export default async function ajax(
input: RequestInfo,
init?: RequestInit
): Promise<Response> {
return fetch(input, init).then(response => {
xg-wang marked this conversation as resolved.
Show resolved Hide resolved
if (response.ok) {
return response.json();
}
throw response;
})
}
168 changes: 0 additions & 168 deletions addon/mixins/adapter-fetch.js

This file was deleted.