Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#47212 [ember-data] Adapter headers should …
Browse files Browse the repository at this point in the history
…be overwriteable with a getter by @wagenet

Instead of being declared as a property we now declare it in an
interface. This works around the issue noted here with TypeScript 4:
microsoft/TypeScript#40220
  • Loading branch information
wagenet authored and danielrearden committed Sep 22, 2020
1 parent 874eedc commit 5e149f0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
22 changes: 14 additions & 8 deletions types/ember-data/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1258,14 +1258,6 @@ export namespace DS {
* An adapter can target other hosts by setting the `host` property.
*/
host: string;
/**
* Some APIs require HTTP headers, e.g. to provide an API
* key. Arbitrary headers can be set as key/value pairs on the
* `RESTAdapter`'s `headers` object and Ember Data will send them
* along with each ajax request. For dynamic headers see [headers
* customization](/api/data/classes/DS.RESTAdapter.html#toc_headers-customization).
*/
headers: {};
/**
* Called by the store in order to fetch the JSON for a given
* type and ID.
Expand Down Expand Up @@ -1496,6 +1488,20 @@ export namespace DS {
*/
pathForType<K extends keyof ModelRegistry>(modelName: K): string;
}

// Instead of declaring `headers as a property we now declare it in an
// interface. This works around the issue noted here with TypeScript 4:
// https://github.com/microsoft/TypeScript/issues/40220
interface RESTAdapter {
/**
* Some APIs require HTTP headers, e.g. to provide an API
* key. Arbitrary headers can be set as key/value pairs on the
* `RESTAdapter`'s `headers` object and Ember Data will send them
* along with each ajax request. For dynamic headers see [headers
* customization](/api/data/classes/DS.RESTAdapter.html#toc_headers-customization).
*/
headers: {};
}
/**
* ## Using Embedded Records
*/
Expand Down
9 changes: 9 additions & 0 deletions types/ember-data/test/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ const AuthTokenHeader = DS.JSONAPIAdapter.extend({
})
});

// Ensure that we are allowed to overwrite headers with a getter
class GetterHeader extends DS.JSONAPIAdapter {
get headers() {
return {
'CUSTOM_HEADER': 'Some header value'
};
}
}

const UseAjax = DS.JSONAPIAdapter.extend({
query(store: DS.Store, type: string, query: object) {
const url = 'https://api.example.com/my-api';
Expand Down
1 change: 1 addition & 0 deletions types/ember-data/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"es6",
"dom"
],
"target": "es5",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
Expand Down

0 comments on commit 5e149f0

Please sign in to comment.