Skip to content

Commit ef708e2

Browse files
committed
Another attempt to fix barrel.ts
This time, use an ambient `declare namespace` to declare the `Ember.RSVP` types, which will avoid the ill-fated attempt to transpile it at runtime using the babel typescript transform. The previous implementation already required us to dynamically install the `RSVP` property on the `Ember` object because the previous transpiler infrastructure didn't reliably handle this situation, so this is probably an improvement either way.
1 parent fc51f7d commit ef708e2

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib/plugins/utils';

packages/@ember/template-compiler/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
".": "./index.ts",
66
"./runtime": "./runtime.ts",
77
"./-internal-primitives": "./-internal-primitives.ts",
8+
"./-internal-utils": "./-internal-utils.ts",
89
"./types": "./lib/types.ts"
910
},
1011
"dependencies": {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from '@ember/template-compiler/-internal-utils';

packages/ember/barrel.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ namespace Ember {
192192
export type ActionHandler = InternalActionHandler;
193193
export const Comparable = InternalComparable;
194194
export type Comparable = InternalComparable;
195-
export const RSVP = _RSVP;
196-
export type RSVP = typeof _RSVP;
197195

198196
// ****@ember/-internals/view****
199197
export const ComponentLookup = views.ComponentLookup;
@@ -591,6 +589,20 @@ namespace Ember {
591589
| undefined;
592590
}
593591

592+
// This syntax is not reliably implemented by TypeScript transpilers, but
593+
// we need to re-export the`RSVP` *namespace* for type compatibility.
594+
// To achieve this, we use a type-only `declare namespace` block to get the
595+
// types to behave correctly, and separately set the `RSVP` property on the
596+
// `Ember` object dynamically. (The types behave correctly because of
597+
// namespace merging semantics.)
598+
// eslint-disable-next-line @typescript-eslint/no-namespace
599+
declare namespace Ember {
600+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
601+
export import RSVP = _RSVP;
602+
}
603+
604+
Reflect.set(Ember, 'RSVP', _RSVP);
605+
594606
interface EmberHandlebars {
595607
template: typeof template;
596608
Utils: {

0 commit comments

Comments
 (0)