Skip to content

Commit e80cedf

Browse files
authored
Merge pull request #764 from chriskrycho/export-TemplateFactory
Export non-user-constructible `TemplateFactory` type
2 parents 3035102 + 611c67d commit e80cedf

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

lib/index.d.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
// Using the same "brand" as the types for `htmlbars-inline-precompile` for
2-
// backwards compatibility. The actual value of the brand doesn't matter; it is
3-
// only important that it (a) is distinct and (b) interoperates with existing
4-
// uses of the `hbs` export from `htmlbars-inline-precompile` [1].
5-
//
6-
// [1]: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/24a21e0b8ec7eccdec781d7513bfa5947f1c6e20/types/ember/index.d.ts#L540:L542
7-
//
8-
// Note that we *intentionally* do not export this; the details are irrelevant
9-
// to consumers. The point is simply to have a *distinct* type that is therefore
10-
// not substitutable for just any other type.
11-
interface TemplateFactory {
12-
__htmlbars_inline_precompile_template_factory: any;
1+
// Shut off automatically-export-everything-mode. We only want to export the
2+
// things we explicitly *say* to export.
3+
export {};
4+
5+
// Allows us to create a branded/opaque type which can *only* be constructed
6+
// without an unsafe cast by calling `hbs()`.
7+
declare const Data: unique symbol;
8+
9+
/**
10+
The result of calling `hbs()`: an internal type for Ember to use with other
11+
framework-level APIs (public and private) like `setComponentTemplate()`.
12+
13+
This type is *not* user-constructible; it is only legal to get it from `hbs`.
14+
*/
15+
declare class TemplateFactory {
16+
private [Data]: 'template-factory';
1317
}
1418

19+
// Only export the type side of the class, so that callers are not misled into
20+
// thinking that they can instantiate, subclass, etc.
21+
export type { TemplateFactory };
22+
1523
export interface PrecompileOptions {
1624
moduleName?: string;
1725
parseOptions?: {

0 commit comments

Comments
 (0)