From 5e149f07a9e56bc528da6609c8dfdd2a408d392d Mon Sep 17 00:00:00 2001 From: Peter Wagenet Date: Thu, 3 Sep 2020 15:23:17 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#47212=20[ember-dat?= =?UTF-8?q?a]=20Adapter=20headers=20should=20be=20overwriteable=20with=20a?= =?UTF-8?q?=20getter=20by=20@wagenet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of being declared 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 --- types/ember-data/index.d.ts | 22 ++++++++++++++-------- types/ember-data/test/adapter.ts | 9 +++++++++ types/ember-data/tsconfig.json | 1 + 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/types/ember-data/index.d.ts b/types/ember-data/index.d.ts index 0062108fd7a2738..9f4853657dade99 100644 --- a/types/ember-data/index.d.ts +++ b/types/ember-data/index.d.ts @@ -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. @@ -1496,6 +1488,20 @@ export namespace DS { */ pathForType(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 */ diff --git a/types/ember-data/test/adapter.ts b/types/ember-data/test/adapter.ts index 647d1623684402f..3b29f52cb50a982 100644 --- a/types/ember-data/test/adapter.ts +++ b/types/ember-data/test/adapter.ts @@ -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'; diff --git a/types/ember-data/tsconfig.json b/types/ember-data/tsconfig.json index 14228f8cd7e20ed..57761c3070b7eba 100644 --- a/types/ember-data/tsconfig.json +++ b/types/ember-data/tsconfig.json @@ -5,6 +5,7 @@ "es6", "dom" ], + "target": "es5", "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true,