-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathtypes.d.ts
40 lines (34 loc) · 1.52 KB
/
types.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { EmptyObject, HasContext } from '@glint/template/-private/integration';
type Constructor<T> = abstract new (...args: never[]) => T;
/**
* A utility for constructing the type of an environment's `resolveOrReturn` from
* the type of its `resolve` function.
*/
export type ResolveOrReturn<T> = T & (<U>(item: U) => (args: EmptyObject) => U);
/**
* Given a tag name, returns an appropriate `Element` subtype.
* NOTE: This will return a union for elements that exist both in HTML and SVG. Technically, this will be too permissive.
*/
export type ElementForTagName<Name extends string> = Name extends keyof HTMLElementTagNameMap
? Name extends keyof SVGElementTagNameMap
? HTMLElementTagNameMap[Name] & SVGElementTagNameMap[Name]
: HTMLElementTagNameMap[Name]
: Name extends keyof SVGElementTagNameMap
? SVGElementTagNameMap[Name]
: Element;
/**
* Given the constructor or instance type of a component backing class, produces the appropriate
* `TemplateContext` type for its template.
*/
export type ResolveContext<T> = T extends HasContext<infer Context>
? Context
: T extends Constructor<HasContext<infer Context>>
? Context
: unknown;
// This encompasses both @glimmer/runtime and @ember/template's notion of `SafeString`s,
// and this coverage is tested in `emit-value.test.ts`.
type SafeString = { toHTML(): string };
/**
* Represents values that can safely be emitted into the DOM i.e. as `<span>{{value}}</span>`.
*/
export type EmittableValue = SafeString | Element | string | number | boolean | null | void;