Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit 6fc4a17

Browse files
committed
Export Signature utility types as @internal
1 parent a5e7969 commit 6fc4a17

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

packages/@glimmer/component/addon/-private/component.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,25 @@ if (DEBUG) {
2828
}
2929

3030
// --- Type utilities for component signatures --- //
31-
32-
// This provides us a way to have a "fallback" which represents an empty object,
33-
// without the downsides of how TS treats `{}`. Specifically: this will
34-
// correctly leverage "excess property checking" so that, given a component
35-
// which has no named args, if someone invokes it with any named args, they will
36-
// get a type error.
31+
// Type-only "symbol" to use with `EmptyObject` below, so that it is *not*
32+
// equivalent to an empty interface.
3733
declare const Empty: unique symbol;
38-
type EmptyObject = { [Empty]?: true };
34+
35+
/**
36+
* This provides us a way to have a "fallback" which represents an empty object,
37+
* without the downsides of how TS treats `{}`. Specifically: this will
38+
* correctly leverage "excess property checking" so that, given a component
39+
* which has no named args, if someone invokes it with any named args, they will
40+
* get a type error.
41+
*
42+
* @internal This is exported so declaration emit works (if it were not emitted,
43+
* declarations which fall back to it would not wor). It is *not* intended for
44+
* public usage, and the specific mechanics it uses may change at any time.
45+
* The location of this export *is* part of the public API, because moving it
46+
* will cause existing declarations, but is not legal for end users to import
47+
* themselves, so ***DO NOT RELY ON IT***.
48+
*/
49+
export type EmptyObject = { [Empty]?: true };
3950

4051
type GetOrElse<Obj, K, Fallback> = K extends keyof Obj ? Obj[K] : Fallback;
4152

@@ -49,8 +60,18 @@ type ArgsFor<S> = 'Args' extends keyof S
4960
: { Named: S['Args']; Positional: [] }
5061
: { Named: EmptyObject; Positional: [] };
5162

52-
/** Given any allowed shorthand form of a signature, desugars it to its full expanded type */
53-
type ExpandSignature<T> = {
63+
/**
64+
* Given any allowed shorthand form of a signature, desugars it to its full
65+
* expanded type.
66+
*
67+
* @internal This is only exported so we can avoid duplicating it in
68+
* [Glint](https://github.com/typed-ember/glint) or other such tooling. It is
69+
* *not* intended for public usage, and the specific mechanics it uses may
70+
* change at any time. Although the signature produced by is part of Glimmer's
71+
* public API the existence and mechanics of this specific symbol are *not*,
72+
* so ***DO NOT RELY ON IT***.
73+
*/
74+
export type ExpandSignature<T> = {
5475
Element: GetOrElse<T, 'Element', null>;
5576
Args: keyof T extends 'Args' | 'Element' | 'Blocks' // Is this a `Signature`?
5677
? ArgsFor<T> // Then use `Signature` args

0 commit comments

Comments
 (0)