Skip to content

Commit

Permalink
chore(type-tests): test TS 4.7 features
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Mar 3, 2023
1 parent a084d58 commit 88a6d76
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion testing/ember-app/tests/type-tests/class-based.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Resource, use } from 'ember-resources';
import { expectTypeOf } from 'expect-type';
import { expectType } from 'ts-expect';

import type { Thunk } from 'ember-resources';
import type { ExpandArgs, Thunk } from 'ember-resources';
// This is private, but we test it for sanity
// because when this was added, I had none.
import type { ArgsFrom } from 'ember-resources/core/class-based/resource';
Expand Down Expand Up @@ -83,3 +83,28 @@ D.from(() => ({ named: { foo: 2 } }));

D.from<D<number>>(() => ({ positional: [1, 2] }));
D.from<D<number>>({}, () => ({ positional: [1, 2] }));



type EArgs<T = unknown> = {
Positional: [];
Named: {
foo: T;
};
};

export class E<MyType = unknown> extends Resource<EArgs<MyType>> {
modify(
positional: ExpandArgs<EArgs<MyType>>['Positional'],
named: ExpandArgs<EArgs<MyType>>['Named']
) {
expectType<never[]>(positional);
expectType<{ foo: MyType }>(named);
}
}

export class EUsage {
foo = 2;
// Available in TS 4.7+
myInstance = E<number>.from(() => ({ foo: this.foo }));
}

0 comments on commit 88a6d76

Please sign in to comment.