@glint/type-test 2.0.0-alpha.1 → 2.0.1-unstable.0e67291
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 +88 -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 +9 -9
- package/LICENSE +0 -21
package/README.md
CHANGED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { DirectInvokable, 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
|
+
type Expectation<T> = {
|
|
20
|
+
[Expectation]: T;
|
|
21
|
+
};
|
|
22
|
+
type UnaryExpectationKind = keyof UnaryExpectations<any>;
|
|
23
|
+
type UnaryExpectation<K extends UnaryExpectationKind> = Expectation<K>;
|
|
24
|
+
type BinaryExpectationKind = keyof BinaryExpectations<any, any>;
|
|
25
|
+
type BinaryExpectation<K extends BinaryExpectationKind> = Expectation<K>;
|
|
26
|
+
type UnmetExpectation<M, T> = [M, T];
|
|
27
|
+
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
|
+
type ExpectTypeOf = DirectInvokable<{
|
|
37
|
+
<T, E extends UnaryExpectationKind>(actual: T, expectation: UnaryExpectation<E>): UnaryExpectations<T>[E] extends [false, infer M] ? UnmetExpectation<M, T> : void;
|
|
38
|
+
<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;
|
|
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 {};
|
|
88
|
+
//# 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,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAKxE,UAAU,iBAAiB,CAAC,CAAC;IAC3B,MAAM,EAAE,CAAC,KAAK,CAAC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|
{
|
|
2
2
|
"name": "@glint/type-test",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1-unstable.0e67291",
|
|
4
4
|
"repository": "typed-ember/glint",
|
|
5
5
|
"description": "Tools for testing inferred types in Glint-enabled templates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,14 +14,19 @@
|
|
|
14
14
|
"README.md",
|
|
15
15
|
"lib"
|
|
16
16
|
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "echo 'no standalone tests within this project'",
|
|
19
|
+
"test:typecheck": "glint -p __tests__",
|
|
20
|
+
"test:tsc": "echo 'no standalone tsc within this project'"
|
|
21
|
+
},
|
|
17
22
|
"dependencies": {
|
|
18
23
|
"expect-type": "^0.15.0"
|
|
19
24
|
},
|
|
20
25
|
"peerDependencies": {
|
|
21
|
-
"@glint/template": "
|
|
26
|
+
"@glint/template": "1.6.1-unstable.0e67291"
|
|
22
27
|
},
|
|
23
28
|
"devDependencies": {
|
|
24
|
-
"@glint/template": "1.6.
|
|
29
|
+
"@glint/template": "1.6.1-unstable.0e67291"
|
|
25
30
|
},
|
|
26
31
|
"release-plan": {
|
|
27
32
|
"semverIncrementAs": {
|
|
@@ -34,10 +39,5 @@
|
|
|
34
39
|
},
|
|
35
40
|
"publishConfig": {
|
|
36
41
|
"access": "public"
|
|
37
|
-
},
|
|
38
|
-
"scripts": {
|
|
39
|
-
"test": "echo 'no standalone tests within this project'",
|
|
40
|
-
"test:typecheck": "glint -p __tests__",
|
|
41
|
-
"test:tsc": "echo 'no standalone tsc within this project'"
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 The Ember TypeScript team and contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|