-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(types, internal): add type tests, try to re-widen typescript ran…
…ge to bring back support for TS 4.5+
- Loading branch information
1 parent
a347f1d
commit bc33140
Showing
22 changed files
with
326 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,6 +215,8 @@ jobs: | |
fail-fast: true | ||
matrix: | ||
typescript-scenario: | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
@@ -239,9 +241,9 @@ jobs: | |
run: pnpm add --save-dev ${{ matrix.typescript-scenario }} | ||
working-directory: ./testing/ember-app | ||
- name: Type checking | ||
run: |- | ||
pnpm --filter ember-app exec glint --version; | ||
pnpm --filter ember-app exec glint | ||
run: >- | ||
pnpm --filter ember-app exec tsc -v; pnpm --filter ember-app exec | ||
glint --version; pnpm --filter ember-app exec glint | ||
release: | ||
name: Release | ||
timeout-minutes: 5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ support: | |
ember-try: true | ||
glint: true | ||
typescript: | ||
- [email protected] | ||
- [email protected] | ||
- [email protected] | ||
# MSW is not compatible with typescript@next | ||
# - typescript@next | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* All of this is baseds off the types for @glimmer/component | ||
* (post starting official typescript support in ember) | ||
*/ | ||
|
||
// Type-only "symbol" to use with `EmptyObject` below, so that it is *not* | ||
// equivalent to an empty interface. | ||
declare const Empty: unique symbol; | ||
|
||
/** | ||
* This provides us a way to have a "fallback" which represents an empty object, | ||
* without the downsides of how TS treats `{}`. Specifically: this will | ||
* correctly leverage "excess property checking" so that, given a component | ||
* which has no named args, if someone invokes it with any named args, they will | ||
* get a type error. | ||
* | ||
* @internal This is exported so declaration emit works (if it were not emitted, | ||
* declarations which fall back to it would not work). It is *not* intended for | ||
* public usage, and the specific mechanics it uses may change at any time. | ||
* The location of this export *is* part of the public API, because moving it | ||
* will break existing declarations, but is not legal for end users to import | ||
* themselves, so ***DO NOT RELY ON IT***. | ||
*/ | ||
export type EmptyObject = { [Empty]?: true }; | ||
|
||
type GetOrElse<Obj, K, Fallback> = K extends keyof Obj ? Obj[K] : Fallback; | ||
|
||
type ArgsFor<S> = | ||
// Signature['Args'] | ||
S extends { Named?: object; Positional?: unknown[] } | ||
? { | ||
Named: GetOrElse<S, 'Named', EmptyObject>; | ||
Positional: GetOrElse<S, 'Positional', []>; | ||
} | ||
: S extends { named?: object; positional?: unknown[] } | ||
? { | ||
Named: GetOrElse<S, 'named', EmptyObject>; | ||
Positional: GetOrElse<S, 'positional', []>; | ||
} | ||
: { Named: EmptyObject; Positional: [] }; | ||
|
||
/** | ||
* Converts a variety of types to the expanded arguments type | ||
* that aligns with the 'Args' portion of the 'Signature' types | ||
* from ember's helpers, modifiers, components, etc | ||
*/ | ||
export type ExpandArgs<T> = T extends any[] | ||
? ArgsFor<{ Positional: T }> | ||
: T extends any | ||
? ArgsFor<T> | ||
: never; | ||
|
||
export type Positional<T> = ExpandArgs<T>['Positional']; | ||
export type Named<T> = ExpandArgs<T>['Named']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Resource } from 'ember-resources'; | ||
import { expectType } from 'ts-expect'; | ||
|
||
class A extends Resource { | ||
a = 1; | ||
} | ||
|
||
expectType<number>(A.from({}).a); | ||
expectType<A>(A.from({})); | ||
|
||
type BArgs = { | ||
positional: [number, string]; | ||
named: { | ||
num: number; | ||
str: string; | ||
}; | ||
}; | ||
|
||
export class B extends Resource<BArgs> { | ||
modify(positional: BArgs['positional'], named: BArgs['named']) { | ||
expectType<[number, string]>(positional); | ||
expectType<number>(named.num); | ||
expectType<string>(named.str); | ||
} | ||
} | ||
|
||
type CArgs = { | ||
Positional: [number, string]; | ||
Named: { | ||
num: number; | ||
str: string; | ||
}; | ||
}; | ||
|
||
export class C extends Resource<CArgs> { | ||
modify(positional: CArgs['Positional'], named: CArgs['Named']) { | ||
expectType<[number, string]>(positional); | ||
expectType<number>(named.num); | ||
expectType<string>(named.str); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { resource } from 'ember-resources'; | ||
import { expectType } from 'ts-expect'; | ||
|
||
/* | ||
* These are all lies, but... useful lies. | ||
* | ||
* in JS, we require the use of a @use decorator | ||
* | ||
* in templates, there is a whole rendering system that figures out the value. | ||
* | ||
* In both situations, the effective value *is* the string | ||
* | ||
*/ | ||
expectType<string>(resource(() => 'hi')); | ||
expectType<string>(resource(() => () => 'hi')); |
Oops, something went wrong.