@glint/template 0.5.1 → 0.6.3

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.
@@ -1,4 +1,13 @@
1
- import { AcceptsBlocks, AnyContext, BoundModifier } from '../integration';
1
+ import {
2
+ AcceptsBlocks,
3
+ AnyContext,
4
+ AnyFunction,
5
+ BoundModifier,
6
+ EmptyObject,
7
+ HasContext,
8
+ Invokable,
9
+ TemplateContext,
10
+ } from '../integration';
2
11
  import { ElementForTagName, EmittableValue } from './types';
3
12
 
4
13
  /*
@@ -50,14 +59,19 @@ export declare function emitElement<Name extends string>(
50
59
  export declare function emitComponent<T extends AcceptsBlocks<any, any>>(
51
60
  component: T
52
61
  ): {
53
- element: T extends AcceptsBlocks<any, infer El> ? El : null;
54
- blockParams: T extends AcceptsBlocks<infer Yields, any> ? Required<Yields> : never;
62
+ element: T extends AcceptsBlocks<any, infer El> ? El : any;
63
+ blockParams: T extends AcceptsBlocks<infer Yields, any> ? Required<Yields> : any;
55
64
  };
56
65
 
57
66
  /**
58
- * Acts as a top-level wrapper for translated template bodies.
67
+ * Acts as a top-level wrapper for translated template bodies. The given
68
+ * callback accepts a template context value as well as an instance of the
69
+ * environment's DSL export.
59
70
  */
60
- export declare function template(f: (𝚪: AnyContext) => void): void;
71
+ export declare function template<
72
+ Signature extends AnyFunction = (args: EmptyObject) => AcceptsBlocks<EmptyObject>,
73
+ Context extends AnyContext = TemplateContext<void, EmptyObject, EmptyObject, void>
74
+ >(f: (𝚪: Context, χ: never) => void): new () => Invokable<Signature> & HasContext<Context>;
61
75
 
62
76
  /*
63
77
  * Used in template bodies to encode a `{{yield}}` statement.
@@ -1,4 +1,5 @@
1
- import { DirectInvokable, EmptyObject, Invokable, Invoke, InvokeDirect } from '../integration';
1
+ import { DirectInvokable, Invokable, Invoke, InvokeDirect } from '../integration';
2
+ import { ResolveOrReturn } from './types';
2
3
 
3
4
  /*
4
5
  * We have multiple ways of representing invokable values, dictated by certain constraints
@@ -45,8 +46,4 @@ export declare function resolve<Args extends unknown[], Instance extends Invokab
45
46
  * value of the appropriate type.
46
47
  */
47
48
 
48
- export declare function resolveOrReturn<T extends DirectInvokable>(item: T): T[typeof InvokeDirect];
49
- export declare function resolveOrReturn<Args extends unknown[], Instance extends Invokable>(
50
- item: (new (...args: Args) => Instance) | null | undefined
51
- ): (...args: Parameters<Instance[typeof Invoke]>) => ReturnType<Instance[typeof Invoke]>;
52
- export declare function resolveOrReturn<T>(item: T): (args: EmptyObject) => T;
49
+ export declare const resolveOrReturn: ResolveOrReturn<typeof resolve>;
@@ -1,7 +1,13 @@
1
- import { HasContext } from '@glint/template/-private/integration';
1
+ import { EmptyObject, HasContext } from '@glint/template/-private/integration';
2
2
 
3
3
  type Constructor<T> = new (...args: any) => T;
4
4
 
5
+ /**
6
+ * A utility for constructing the type of an environment's `resolveOrReturn` from
7
+ * the type of its `resolve` function.
8
+ */
9
+ export type ResolveOrReturn<T> = T & (<U>(item: U) => (args: EmptyObject) => U);
10
+
5
11
  /**
6
12
  * Given a tag name, returns an appropriate `Element` subtype.
7
13
  * NOTE: This will return a union for elements that exist both in HTML and SVG. Technically, this will be too permissive.
@@ -15,10 +21,14 @@ export type ElementForTagName<Name extends string> = Name extends keyof HTMLElem
15
21
  : Element;
16
22
 
17
23
  /**
18
- * Given the instance type of a component backing class, produces the appropriate
24
+ * Given the constructor or instance type of a component backing class, produces the appropriate
19
25
  * `TemplateContext` type for its template.
20
26
  */
21
- export type ResolveContext<T> = T extends HasContext<infer Context> ? Context : unknown;
27
+ export type ResolveContext<T> = T extends HasContext<infer Context>
28
+ ? Context
29
+ : T extends Constructor<HasContext<infer Context>>
30
+ ? Context
31
+ : unknown;
22
32
 
23
33
  // This encompasses both @glimmer/runtime and @ember/template's notion of `SafeString`s,
24
34
  // and this coverage is tested in `emit-value.test.ts`.
@@ -37,7 +37,7 @@ export type BoundModifier<El extends Element> = { [Modifier]: (el: El) => void }
37
37
  * Denotes that the associated entity may be invoked with the given
38
38
  * blocks, yielding params of the appropriate type.
39
39
  */
40
- export type AcceptsBlocks<BlockImpls extends AnyBlocks, El extends Element | null = null> = {
40
+ export type AcceptsBlocks<BlockImpls, El extends Element | null = null> = {
41
41
  [Element]: El;
42
42
  (blocks: BlockImpls): { [Blocks]: true };
43
43
  };
@@ -1,5 +1,5 @@
1
1
  import { AcceptsBlocks, DirectInvokable } from '../integration';
2
2
 
3
3
  export type InElementKeyword = DirectInvokable<{
4
- (args: { insertBefore?: null }, element: Element): AcceptsBlocks<{ default: [] }>;
4
+ (args: { insertBefore?: null | undefined }, element: Element): AcceptsBlocks<{ default: [] }>;
5
5
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glint/template",
3
- "version": "0.5.1",
3
+ "version": "0.6.3",
4
4
  "repository": "typed-ember/glint",
5
5
  "description": "Type definitions to back typechecking for Glimmer templates",
6
6
  "license": "MIT",