@glint/type-test 2.0.0-alpha.1 → 2.0.0-alpha.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.
- package/README.md +1 -0
- package/lib/index.d.ts +109 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -0
- package/package.json +7 -3
package/README.md
CHANGED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { DirectInvokable, HasContext } from '@glint/template/-private/integration';
|
|
2
|
+
import { StrictEqualUsingTSInternalIdenticalToOperator, Extends, IsAny, IsNever, IsUnknown } from 'expect-type';
|
|
3
|
+
interface UnaryExpectations<T> {
|
|
4
|
+
string: [
|
|
5
|
+
StrictEqualUsingTSInternalIdenticalToOperator<T, string>,
|
|
6
|
+
'Expected type to be `string`, but got'
|
|
7
|
+
];
|
|
8
|
+
number: [
|
|
9
|
+
StrictEqualUsingTSInternalIdenticalToOperator<T, number>,
|
|
10
|
+
'Expected type to be `number`, but got'
|
|
11
|
+
];
|
|
12
|
+
boolean: [
|
|
13
|
+
StrictEqualUsingTSInternalIdenticalToOperator<T, boolean>,
|
|
14
|
+
'Expected type to be `boolean`, but got'
|
|
15
|
+
];
|
|
16
|
+
symbol: [
|
|
17
|
+
StrictEqualUsingTSInternalIdenticalToOperator<T, symbol>,
|
|
18
|
+
'Expected type to be a `symbol`, but got'
|
|
19
|
+
];
|
|
20
|
+
any: [IsAny<T>, 'Expected type to be `any`, but got'];
|
|
21
|
+
unknown: [IsUnknown<T>, 'Expected type to be `unknown`, but got'];
|
|
22
|
+
never: [IsNever<T>, 'Expected type to be `never`, but got'];
|
|
23
|
+
null: [
|
|
24
|
+
StrictEqualUsingTSInternalIdenticalToOperator<T, null>,
|
|
25
|
+
'Expected type to be `null`, but got'
|
|
26
|
+
];
|
|
27
|
+
undefined: [
|
|
28
|
+
StrictEqualUsingTSInternalIdenticalToOperator<T, undefined>,
|
|
29
|
+
'Expected type to be `undefined`, but got'
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
interface BinaryExpectations<T, U> {
|
|
33
|
+
equal: [
|
|
34
|
+
StrictEqualUsingTSInternalIdenticalToOperator<T, U>,
|
|
35
|
+
'Expected first type to be identical to the second'
|
|
36
|
+
];
|
|
37
|
+
assignableTo: [Extends<T, U>, 'Expected first type to be assignable to the second'];
|
|
38
|
+
}
|
|
39
|
+
declare const Expectation: unique symbol;
|
|
40
|
+
type Expectation<T> = {
|
|
41
|
+
[Expectation]: T;
|
|
42
|
+
};
|
|
43
|
+
type UnaryExpectationKind = keyof UnaryExpectations<any>;
|
|
44
|
+
type UnaryExpectation<K extends UnaryExpectationKind> = Expectation<K>;
|
|
45
|
+
type BinaryExpectationKind = keyof BinaryExpectations<any, any>;
|
|
46
|
+
type BinaryExpectation<K extends BinaryExpectationKind> = Expectation<K>;
|
|
47
|
+
type UnmetExpectation<M, T> = [M, T];
|
|
48
|
+
type TypeTestTemplate<T> = abstract new () => HasContext<{
|
|
49
|
+
this: T;
|
|
50
|
+
args: {
|
|
51
|
+
expectTypeOf: typeof expectTypeOf;
|
|
52
|
+
to: typeof to;
|
|
53
|
+
};
|
|
54
|
+
blocks: {};
|
|
55
|
+
element: unknown;
|
|
56
|
+
}>;
|
|
57
|
+
type ExpectTypeOf = DirectInvokable<{
|
|
58
|
+
<T, E extends UnaryExpectationKind>(actual: T, expectation: UnaryExpectation<E>): UnaryExpectations<T>[E] extends [false, infer M] ? UnmetExpectation<M, T> : void;
|
|
59
|
+
<T, E extends BinaryExpectationKind, U>(actual: T, expectation: BinaryExpectation<E>, expected: U): BinaryExpectations<T, U>[E] extends [false, infer M] ? UnmetExpectation<M, [T, U]> : void;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Given a value, an expectation, and potentially a second value as the
|
|
63
|
+
* target of that expectation, confirms whether the type of that value
|
|
64
|
+
* meets the constraints set by the given expectation.
|
|
65
|
+
*
|
|
66
|
+
* ```handlebars
|
|
67
|
+
* {{expectTypeOf 123 to.beNumber}}
|
|
68
|
+
* {{expectTypeOf 123 to.equalTypeOf (add 1 2)}}
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare const expectTypeOf: ExpectTypeOf;
|
|
72
|
+
/**
|
|
73
|
+
* Provides a set of possible expectations to apply against the
|
|
74
|
+
* type of a value passed to `{{expectTypeOf}}`.
|
|
75
|
+
*/
|
|
76
|
+
export declare const to: {
|
|
77
|
+
equalTypeOf: BinaryExpectation<'equal'>;
|
|
78
|
+
beAssignableToTypeOf: BinaryExpectation<'assignableTo'>;
|
|
79
|
+
beString: UnaryExpectation<'string'>;
|
|
80
|
+
beNumber: UnaryExpectation<'number'>;
|
|
81
|
+
beBoolean: UnaryExpectation<'boolean'>;
|
|
82
|
+
beSymbol: UnaryExpectation<'symbol'>;
|
|
83
|
+
beAny: UnaryExpectation<'any'>;
|
|
84
|
+
beUnknown: UnaryExpectation<'unknown'>;
|
|
85
|
+
beNever: UnaryExpectation<'never'>;
|
|
86
|
+
beNull: UnaryExpectation<'null'>;
|
|
87
|
+
beUndefined: UnaryExpectation<'undefined'>;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Given a loose-mode template (e.g. as defined using `hbs`), this
|
|
91
|
+
* wrapper sets the context of that template appropriately. It receives
|
|
92
|
+
* the `expectTypeOf` and `to` imports from this module as args, and
|
|
93
|
+
* optionally takes an initial `context` parameter that determines the
|
|
94
|
+
* type of the `{{this}}` value in the template.
|
|
95
|
+
*
|
|
96
|
+
* ```typescript
|
|
97
|
+
* typeTest(
|
|
98
|
+
* { message: 'hello' },
|
|
99
|
+
* hbs`
|
|
100
|
+
* {{@expectTypeOf this.message @to.beString}}
|
|
101
|
+
* `
|
|
102
|
+
* );
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function typeTest<T>(context: T, template: TypeTestTemplate<T>): void;
|
|
106
|
+
export declare function typeTest(template: TypeTestTemplate<null>): void;
|
|
107
|
+
export declare function typeTest(...args: Array<unknown>): void;
|
|
108
|
+
export {};
|
|
109
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EACL,6CAA6C,EAC7C,OAAO,EACP,KAAK,EACL,OAAO,EACP,SAAS,EACV,MAAM,aAAa,CAAC;AAKrB,UAAU,iBAAiB,CAAC,CAAC;IAC3B,MAAM,EAAE;QACN,6CAA6C,CAAC,CAAC,EAAE,MAAM,CAAC;QACxD,uCAAuC;KACxC,CAAC;IACF,MAAM,EAAE;QACN,6CAA6C,CAAC,CAAC,EAAE,MAAM,CAAC;QACxD,uCAAuC;KACxC,CAAC;IACF,OAAO,EAAE;QACP,6CAA6C,CAAC,CAAC,EAAE,OAAO,CAAC;QACzD,wCAAwC;KACzC,CAAC;IACF,MAAM,EAAE;QACN,6CAA6C,CAAC,CAAC,EAAE,MAAM,CAAC;QACxD,yCAAyC;KAC1C,CAAC;IACF,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,oCAAoC,CAAC,CAAC;IACtD,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,wCAAwC,CAAC,CAAC;IAClE,KAAK,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,sCAAsC,CAAC,CAAC;IAC5D,IAAI,EAAE;QACJ,6CAA6C,CAAC,CAAC,EAAE,IAAI,CAAC;QACtD,qCAAqC;KACtC,CAAC;IACF,SAAS,EAAE;QACT,6CAA6C,CAAC,CAAC,EAAE,SAAS,CAAC;QAC3D,0CAA0C;KAC3C,CAAC;CACH;AAED,UAAU,kBAAkB,CAAC,CAAC,EAAE,CAAC;IAC/B,KAAK,EAAE;QACL,6CAA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,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AACrF,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AACzE,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC"}
|
package/lib/index.js
ADDED
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glint/type-test",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.3",
|
|
4
4
|
"repository": "typed-ember/glint",
|
|
5
5
|
"description": "Tools for testing inferred types in Glint-enabled templates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,13 +15,17 @@
|
|
|
15
15
|
"lib"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"expect-type": "^
|
|
18
|
+
"expect-type": "^1.2.1"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"@glint/template": "*"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"
|
|
24
|
+
"ember-cli-htmlbars": "^6.0.1",
|
|
25
|
+
"@glint/environment-ember-template-imports": "2.0.0-alpha.3",
|
|
26
|
+
"@glint/template": "1.6.0-alpha.2",
|
|
27
|
+
"@glint/core": "2.0.0-alpha.3",
|
|
28
|
+
"@glint/environment-ember-loose": "2.0.0-alpha.3"
|
|
25
29
|
},
|
|
26
30
|
"release-plan": {
|
|
27
31
|
"semverIncrementAs": {
|