@glint/template 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/-private/dsl/emit.d.ts +26 -6
- package/-private/dsl/types.d.ts +1 -11
- package/-private/integration.d.ts +6 -4
- package/package.json +2 -3
package/-private/dsl/emit.d.ts
CHANGED
|
@@ -64,16 +64,36 @@ export declare function emitComponent<T extends AcceptsBlocks<any, any>>(
|
|
|
64
64
|
blockParams: T extends AcceptsBlocks<infer Yields, any> ? Required<Yields> : any;
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
*
|
|
69
|
-
*
|
|
67
|
+
/*
|
|
68
|
+
* Wraps a template body that appears as a standalone expression and is therefore not
|
|
69
|
+
* associated with any backing value.
|
|
70
|
+
*
|
|
71
|
+
* The given callback accepts a template context value as well as an instance of the
|
|
70
72
|
* environment's DSL export.
|
|
71
73
|
*/
|
|
72
|
-
export declare function
|
|
74
|
+
export declare function templateExpression<
|
|
73
75
|
Signature extends AnyFunction = (args: EmptyObject) => AcceptsBlocks<EmptyObject>,
|
|
74
76
|
Context extends AnyContext = TemplateContext<void, EmptyObject, EmptyObject, void>
|
|
75
77
|
>(f: (𝚪: Context, χ: never) => void): new () => Invokable<Signature> & HasContext<Context>;
|
|
76
78
|
|
|
79
|
+
/*
|
|
80
|
+
* Wraps a template body that's backed by a known value (typically a class), either
|
|
81
|
+
* via a `.hbs` association to a default export or via embedding e.g. with `<template>`.
|
|
82
|
+
*
|
|
83
|
+
* The given callback accepts a template context value as well as an instance of the
|
|
84
|
+
* environment's DSL export.
|
|
85
|
+
*
|
|
86
|
+
* Note that this signature is structured carefully to trigger TypeScript's higher-order function
|
|
87
|
+
* type inference so that any type parameters on the given backing value (if it's a class) will
|
|
88
|
+
* be preserved and reflected in the template body. Both the `Args` type and the constructor return
|
|
89
|
+
* value are necessary for this, despite the fact that we don't actually do anything with those
|
|
90
|
+
* types (see https://github.com/microsoft/TypeScript/pull/30215).
|
|
91
|
+
*/
|
|
92
|
+
export declare function templateForBackingValue<Args extends unknown[], Context extends AnyContext>(
|
|
93
|
+
backingValue: abstract new (...args: Args) => HasContext<Context>,
|
|
94
|
+
body: (𝚪: Context, χ: never) => void
|
|
95
|
+
): abstract new () => unknown;
|
|
96
|
+
|
|
77
97
|
/*
|
|
78
98
|
* Used in template bodies to encode a `{{yield}}` statement.
|
|
79
99
|
*
|
|
@@ -83,10 +103,10 @@ export declare function template<
|
|
|
83
103
|
*
|
|
84
104
|
* yieldToBlock(𝚪, 'name', foo, bar);
|
|
85
105
|
*/
|
|
86
|
-
export declare function yieldToBlock<Context extends AnyContext, K extends keyof Context['
|
|
106
|
+
export declare function yieldToBlock<Context extends AnyContext, K extends keyof Context['blocks']>(
|
|
87
107
|
𝚪: Context,
|
|
88
108
|
to: K,
|
|
89
|
-
...values: NonNullable<Context['
|
|
109
|
+
...values: NonNullable<Context['blocks'][K]>
|
|
90
110
|
): void;
|
|
91
111
|
|
|
92
112
|
/*
|
package/-private/dsl/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EmptyObject
|
|
1
|
+
import { EmptyObject } from '@glint/template/-private/integration';
|
|
2
2
|
|
|
3
3
|
type Constructor<T> = abstract new (...args: never[]) => T;
|
|
4
4
|
|
|
@@ -19,13 +19,3 @@ export type ElementForTagName<Name extends string> = Name extends keyof HTMLElem
|
|
|
19
19
|
: Name extends keyof SVGElementTagNameMap
|
|
20
20
|
? SVGElementTagNameMap[Name]
|
|
21
21
|
: Element;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Given the constructor or instance type of a component backing class, produces the appropriate
|
|
25
|
-
* `TemplateContext` type for its template.
|
|
26
|
-
*/
|
|
27
|
-
export type ResolveContext<T> = T extends HasContext<infer Context>
|
|
28
|
-
? Context
|
|
29
|
-
: T extends Constructor<HasContext<infer Context>>
|
|
30
|
-
? Context
|
|
31
|
-
: unknown;
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// module exports the symbols and types necessary to declare a class or
|
|
3
3
|
// other entity as integrating with Glint's template system.
|
|
4
4
|
|
|
5
|
+
import { EmptyObject } from '@glimmer/component/-private/component';
|
|
6
|
+
export { EmptyObject };
|
|
7
|
+
|
|
5
8
|
/** Any function, which is the tighest bound we can put on an object's `[Invoke]` field. */
|
|
6
9
|
export type AnyFunction = (...params: any) => any;
|
|
7
10
|
|
|
@@ -23,8 +26,7 @@ export type HasContext<T extends AnyContext = AnyContext> = { [Context]: T };
|
|
|
23
26
|
// These shenanigans are necessary to get TS to report when named args
|
|
24
27
|
// are passed to a signature that doesn't expect any, because `{}` is
|
|
25
28
|
// special-cased in the type system not to trigger EPC.
|
|
26
|
-
|
|
27
|
-
export type EmptyObject = { [EmptyObject]?: void };
|
|
29
|
+
|
|
28
30
|
export type GuardEmpty<T> = T extends any ? (keyof T extends never ? EmptyObject : T) : never;
|
|
29
31
|
|
|
30
32
|
declare const Element: unique symbol;
|
|
@@ -47,10 +49,10 @@ export type AcceptsBlocks<BlockImpls, El = null> = {
|
|
|
47
49
|
* Determines the type of `this` and any `@arg`s used in a template,
|
|
48
50
|
* as well as valid `{{yield}}` invocations and `...attributes` usage.
|
|
49
51
|
*/
|
|
50
|
-
export type TemplateContext<This, Args,
|
|
52
|
+
export type TemplateContext<This, Args, Blocks, Element> = {
|
|
51
53
|
this: This;
|
|
52
54
|
args: Args;
|
|
53
|
-
|
|
55
|
+
blocks: Blocks;
|
|
54
56
|
element: Element;
|
|
55
57
|
};
|
|
56
58
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glint/template",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"repository": "typed-ember/glint",
|
|
5
5
|
"description": "Type definitions to back typechecking for Glimmer templates",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": "Dan Freeman (https://github.com/dfreeman)",
|
|
8
8
|
"types": "-private/index.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"lint": "eslint . --max-warnings 0 && prettier --check .",
|
|
11
10
|
"test": "tsc --project __tests__"
|
|
12
11
|
},
|
|
13
12
|
"files": [
|
|
@@ -20,7 +19,7 @@
|
|
|
20
19
|
},
|
|
21
20
|
"devDependencies": {
|
|
22
21
|
"@glimmer/component": "^1.1.2",
|
|
23
|
-
"@glimmerx/component": "^0.
|
|
22
|
+
"@glimmerx/component": "^0.6.7",
|
|
24
23
|
"@types/ember__component": "~4.0.8",
|
|
25
24
|
"expect-type": "0.11.0",
|
|
26
25
|
"sums-up": "^2.1.0"
|