@glint/type-test 0.9.7

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/lib/index.d.ts ADDED
@@ -0,0 +1,87 @@
1
+ import { DirectInvokable, EmptyObject, HasContext } from '@glint/template/-private/integration';
2
+ import { Equal, Extends, IsAny, IsNever, IsUnknown } from 'expect-type';
3
+ interface UnaryExpectations<T> {
4
+ string: [Equal<T, string>, 'Expected type to be `string`, but got'];
5
+ number: [Equal<T, number>, 'Expected type to be `number`, but got'];
6
+ boolean: [Equal<T, boolean>, 'Expected type to be `boolean`, but got'];
7
+ symbol: [Equal<T, symbol>, 'Expected type to be a `symbol`, but got'];
8
+ any: [IsAny<T>, 'Expected type to be `any`, but got'];
9
+ unknown: [IsUnknown<T>, 'Expected type to be `unknown`, but got'];
10
+ never: [IsNever<T>, 'Expected type to be `never`, but got'];
11
+ null: [Equal<T, null>, 'Expected type to be `null`, but got'];
12
+ undefined: [Equal<T, undefined>, 'Expected type to be `undefined`, but got'];
13
+ }
14
+ interface BinaryExpectations<T, U> {
15
+ equal: [Equal<T, U>, 'Expected first type to be identical to the second'];
16
+ assignableTo: [Extends<T, U>, 'Expected first type to be assignable to the second'];
17
+ }
18
+ declare const Expectation: unique symbol;
19
+ declare type Expectation<T> = {
20
+ [Expectation]: T;
21
+ };
22
+ declare type UnaryExpectationKind = keyof UnaryExpectations<any>;
23
+ declare type UnaryExpectation<K extends UnaryExpectationKind> = Expectation<K>;
24
+ declare type BinaryExpectationKind = keyof BinaryExpectations<any, any>;
25
+ declare type BinaryExpectation<K extends BinaryExpectationKind> = Expectation<K>;
26
+ declare type UnmetExpectation<M, T> = [M, T];
27
+ declare type TypeTestTemplate<T> = abstract new () => HasContext<{
28
+ this: T;
29
+ args: {
30
+ expectTypeOf: typeof expectTypeOf;
31
+ to: typeof to;
32
+ };
33
+ blocks: {};
34
+ element: unknown;
35
+ }>;
36
+ declare type ExpectTypeOf = DirectInvokable<{
37
+ <T, E extends UnaryExpectationKind>(named: EmptyObject, actual: T, expectation: UnaryExpectation<E>): UnaryExpectations<T>[E] extends [false, infer M] ? UnmetExpectation<M, T> : void;
38
+ <T, E extends BinaryExpectationKind, U>(named: EmptyObject, actual: T, expectation: BinaryExpectation<E>, expected: U): BinaryExpectations<T, U>[E] extends [false, infer M] ? UnmetExpectation<M, [T, U]> : void;
39
+ }>;
40
+ /**
41
+ * Given a value, an expectation, and potentially a second value as the
42
+ * target of that expectation, confirms whether the type of that value
43
+ * meets the constraints set by the given expectation.
44
+ *
45
+ * ```handlebars
46
+ * {{expectTypeOf 123 to.beNumber}}
47
+ * {{expectTypeOf 123 to.equalTypeOf (add 1 2)}}
48
+ * ```
49
+ */
50
+ export declare const expectTypeOf: ExpectTypeOf;
51
+ /**
52
+ * Provides a set of possible expectations to apply against the
53
+ * type of a value passed to `{{expectTypeOf}}`.
54
+ */
55
+ export declare const to: {
56
+ equalTypeOf: BinaryExpectation<'equal'>;
57
+ beAssignableToTypeOf: BinaryExpectation<'assignableTo'>;
58
+ beString: UnaryExpectation<'string'>;
59
+ beNumber: UnaryExpectation<'number'>;
60
+ beBoolean: UnaryExpectation<'boolean'>;
61
+ beSymbol: UnaryExpectation<'symbol'>;
62
+ beAny: UnaryExpectation<'any'>;
63
+ beUnknown: UnaryExpectation<'unknown'>;
64
+ beNever: UnaryExpectation<'never'>;
65
+ beNull: UnaryExpectation<'null'>;
66
+ beUndefined: UnaryExpectation<'undefined'>;
67
+ };
68
+ /**
69
+ * Given a loose-mode template (e.g. as defined using `hbs`), this
70
+ * wrapper sets the context of that template appropriately. It receives
71
+ * the `expectTypeOf` and `to` imports from this module as args, and
72
+ * optionally takes an initial `context` parameter that determines the
73
+ * type of the `{{this}}` value in the template.
74
+ *
75
+ * ```typescript
76
+ * typeTest(
77
+ * { message: 'hello' },
78
+ * hbs`
79
+ * {{@expectTypeOf this.message @to.beString}}
80
+ * `
81
+ * );
82
+ * ```
83
+ */
84
+ export declare function typeTest<T>(context: T, template: TypeTestTemplate<T>): void;
85
+ export declare function typeTest(template: TypeTestTemplate<null>): void;
86
+ export declare function typeTest(...args: Array<unknown>): void;
87
+ export {};
package/lib/index.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@glint/type-test",
3
+ "version": "0.9.7",
4
+ "repository": "typed-ember/glint",
5
+ "description": "Tools for testing inferred types in Glint-enabled templates",
6
+ "license": "MIT",
7
+ "author": "Dan Freeman (https://github.com/dfreeman)",
8
+ "type": "commonjs",
9
+ "main": "lib/index.js",
10
+ "exports": {
11
+ ".": "./lib/index.js"
12
+ },
13
+ "files": [
14
+ "README.md",
15
+ "lib"
16
+ ],
17
+ "scripts": {
18
+ "test": "glint -p __tests__"
19
+ },
20
+ "dependencies": {
21
+ "expect-type": "^0.15.0"
22
+ },
23
+ "peerDependencies": {
24
+ "@glint/template": "^0.9.7"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
29
+ }