Skip to content

Commit

Permalink
upgrade to tstyche2 and fix PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau committed Apr 15, 2024
1 parent 16bdcf7 commit ed3f2a7
Show file tree
Hide file tree
Showing 21 changed files with 498 additions and 538 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -127,7 +127,7 @@
"rollup": "3.28.1",
"size-limit": "^8.2.6",
"transducers-js": "0.4.174",
"tstyche": "^1.0.0",
"tstyche": "^2.0.0-beta.0",
"typescript": "5.1"
},
"size-limit": [
Expand Down
26 changes: 14 additions & 12 deletions type-definitions/ts-tests/covariance.ts
Expand Up @@ -35,51 +35,53 @@ class C {
}

test('List covariance', () => {
expect<List<A>>().type.toBeAssignable(List<B>());
expect<List<A>>().type.toBeAssignableWith(List<B>());

expect(List([new B()])).type.toEqual<List<B>>();
expect(List([new B()])).type.toBe<List<B>>();

expect<List<C>>().type.not.toBeAssignable(List<B>());
});

test('Map covariance', () => {
expect<Map<string, A>>().type.toBeAssignable<Map<string, B>>();
expect<Map<string, A>>().type.toBeAssignableWith<Map<string, B>>();

expect(Map({ b: new B() })).type.toEqual<MapOf<{ b: B }>>();
expect(Map({ b: new B() })).type.toBe<MapOf<{ b: B }>>();

expect<Map<string, C>>().type.not.toBeAssignable<Map<string, B>>();
});

test('Set covariance', () => {
expect<Set<A>>().type.toBeAssignable<Set<B>>();
expect<Set<A>>().type.toBeAssignableWith<Set<B>>();

expect(Set([new B()])).type.toEqual<Set<B>>();
expect(Set([new B()])).type.toBe<Set<B>>();

expect<Set<C>>().type.not.toBeAssignable<Set<B>>();
});

test('Stack covariance', () => {
expect<Stack<A>>().type.toBeAssignable<Stack<B>>();
expect<Stack<A>>().type.toBeAssignableWith<Stack<B>>();

expect(Stack([new B()])).type.toEqual<Stack<B>>();
expect(Stack([new B()])).type.toBe<Stack<B>>();

expect<Stack<C>>().type.not.toBeAssignable<Stack<B>>();
});

test('OrderedMap covariance', () => {
expect<OrderedMap<string, A>>().type.toBeAssignable<OrderedMap<string, B>>();
expect<OrderedMap<string, A>>().type.toBeAssignableWith<
OrderedMap<string, B>
>();

expect(OrderedMap({ b: new B() })).type.toEqual<OrderedMap<string, B>>();
expect(OrderedMap({ b: new B() })).type.toBe<OrderedMap<string, B>>();

expect<OrderedMap<string, C>>().type.not.toBeAssignable<
OrderedMap<string, B>
>();
});

test('OrderedSet covariance', () => {
expect<OrderedSet<A>>().type.toBeAssignable<OrderedSet<B>>();
expect<OrderedSet<A>>().type.toBeAssignableWith<OrderedSet<B>>();

expect(OrderedSet([new B()])).type.toEqual<OrderedSet<B>>();
expect(OrderedSet([new B()])).type.toBe<OrderedSet<B>>();

expect<OrderedSet<C>>().type.not.toBeAssignable<OrderedSet<B>>();
});
38 changes: 19 additions & 19 deletions type-definitions/ts-tests/deepCopy.ts
Expand Up @@ -8,55 +8,55 @@ describe('DeepCopy', () => {
a: number;
b: number;
}>
>().type.toEqual<{
>().type.toBe<{
a: number;
b: number;
}>();
});

test('iterables', () => {
expect<DeepCopy<string[]>>().type.toEqual<string[]>();
expect<DeepCopy<string[]>>().type.toBe<string[]>();

expect<DeepCopy<Collection.Indexed<number>>>().type.toEqual<number[]>();
expect<DeepCopy<Collection.Indexed<number>>>().type.toBe<number[]>();
});

test('immutable first-level types', () => {
expect<DeepCopy<Map<string, string>>>().type.toEqual<{
expect<DeepCopy<Map<string, string>>>().type.toBe<{
[x: string]: string;
}>();

// should be `{ [x: string]: object }`, but there is an issue with circular references
expect<DeepCopy<Map<object, object>>>().type.toEqual<{
expect<DeepCopy<Map<object, object>>>().type.toBe<{
[x: string]: unknown;
}>();

// should be `{ [x: string]: object; [x: number]: object }`, but there is an issue with circular references
expect<DeepCopy<Map<object | number, object>>>().type.toEqual<{
expect<DeepCopy<Map<object | number, object>>>().type.toBe<{
[x: string]: unknown;
[x: number]: unknown;
}>();

expect<DeepCopy<List<string>>>().type.toEqual<string[]>();
expect<DeepCopy<List<string>>>().type.toBe<string[]>();

expect<DeepCopy<Set<string>>>().type.toEqual<string[]>();
expect<DeepCopy<Set<string>>>().type.toBe<string[]>();
});

test('keyed', () => {
expect<DeepCopy<Collection.Keyed<string, number>>>().type.toEqual<{
expect<DeepCopy<Collection.Keyed<string, number>>>().type.toBe<{
[x: string]: number;
}>();

expect<DeepCopy<Collection.Keyed<string | number, number>>>().type.toEqual<{
expect<DeepCopy<Collection.Keyed<string | number, number>>>().type.toBe<{
[x: string]: number;
[x: number]: number;
}>();

expect<DeepCopy<Seq.Keyed<string | number, number>>>().type.toEqual<{
expect<DeepCopy<Seq.Keyed<string | number, number>>>().type.toBe<{
[x: string]: number;
[x: number]: number;
}>();

expect<DeepCopy<Map<string | number, number>>>().type.toEqual<{
expect<DeepCopy<Map<string | number, number>>>().type.toBe<{
[x: string]: number;
[x: number]: number;
}>();
Expand All @@ -70,10 +70,10 @@ describe('DeepCopy', () => {
list: List<string>;
set: Set<string>;
}>
>().type.toEqual<{ map: unknown; list: unknown; set: unknown }>();
>().type.toBe<{ map: unknown; list: unknown; set: unknown }>();

// should be `{ map: { [x: string]: string } }`, but there is an issue with circular references
expect<DeepCopy<Map<'map', Map<string, string>>>>().type.toEqual<{
expect<DeepCopy<Map<'map', Map<string, string>>>>().type.toBe<{
map: unknown;
}>();
});
Expand All @@ -83,7 +83,7 @@ describe('DeepCopy', () => {
type Tag = Record<{ name: string; article: Article }>;

// should handle circular references here somehow
expect<DeepCopy<Article>>().type.toEqual<{ title: string; tag: unknown }>();
expect<DeepCopy<Article>>().type.toBe<{ title: string; tag: unknown }>();
});

test('circular references #1957', () => {
Expand All @@ -99,14 +99,14 @@ describe('DeepCopy', () => {
foo: null,
}) {}

expect<DeepCopy<Foo1>>().type.toEqual<{ foo: unknown }>();
expect<DeepCopy<Foo2>>().type.toEqual<{ foo?: unknown }>();
expect<DeepCopy<Foo3>>().type.toEqual<{ foo: unknown }>();
expect<DeepCopy<Foo1>>().type.toBe<{ foo: unknown }>();
expect<DeepCopy<Foo2>>().type.toBe<{ foo?: unknown }>();
expect<DeepCopy<Foo3>>().type.toBe<{ foo: unknown }>();

class FooWithList extends Record<{ foo: undefined | List<FooWithList> }>({
foo: undefined,
}) {}

expect<DeepCopy<FooWithList>>().type.toEqual<{ foo: unknown }>();
expect<DeepCopy<FooWithList>>().type.toBe<{ foo: unknown }>();
});
});
36 changes: 16 additions & 20 deletions type-definitions/ts-tests/empty.ts
Expand Up @@ -2,43 +2,39 @@ import { expect, test } from 'tstyche';
import { Seq, Collection } from 'immutable';

test('typed empty Seq', () => {
expect(Seq()).type.toEqual<Seq<unknown, unknown>>();
expect(Seq()).type.toBe<Seq<unknown, unknown>>();

expect(Seq<number, string>()).type.toEqual<Seq<number, string>>();
expect(Seq<number, string>()).type.toBe<Seq<number, string>>();

expect(Seq.Indexed()).type.toEqual<Seq.Indexed<unknown>>();
expect(Seq.Indexed()).type.toBe<Seq.Indexed<unknown>>();

expect(Seq.Indexed<string>()).type.toEqual<Seq.Indexed<string>>();
expect(Seq.Indexed<string>()).type.toBe<Seq.Indexed<string>>();

expect(Seq.Keyed()).type.toEqual<Seq.Keyed<unknown, unknown>>();
expect(Seq.Keyed()).type.toBe<Seq.Keyed<unknown, unknown>>();

expect(Seq.Keyed<number, string>()).type.toEqual<Seq.Keyed<number, string>>();
expect(Seq.Keyed<number, string>()).type.toBe<Seq.Keyed<number, string>>();

expect(Seq.Set()).type.toEqual<Seq.Set<unknown>>();
expect(Seq.Set()).type.toBe<Seq.Set<unknown>>();

expect(Seq.Set<string>()).type.toEqual<Seq.Set<string>>();
expect(Seq.Set<string>()).type.toBe<Seq.Set<string>>();
});

test('typed empty Collection', () => {
expect(Collection()).type.toEqual<Collection<unknown, unknown>>();
expect(Collection()).type.toBe<Collection<unknown, unknown>>();

expect(Collection<number, string>()).type.toEqual<
Collection<number, string>
>();
expect(Collection<number, string>()).type.toBe<Collection<number, string>>();

expect(Collection.Indexed()).type.toEqual<Collection.Indexed<unknown>>();
expect(Collection.Indexed()).type.toBe<Collection.Indexed<unknown>>();

expect(Collection.Indexed<string>()).type.toEqual<
Collection.Indexed<string>
>();
expect(Collection.Indexed<string>()).type.toBe<Collection.Indexed<string>>();

expect(Collection.Keyed()).type.toEqual<Collection.Keyed<unknown, unknown>>();
expect(Collection.Keyed()).type.toBe<Collection.Keyed<unknown, unknown>>();

expect(Collection.Keyed<number, string>()).type.toEqual<
expect(Collection.Keyed<number, string>()).type.toBe<
Collection.Keyed<number, string>
>();

expect(Collection.Set()).type.toEqual<Collection.Set<unknown>>();
expect(Collection.Set()).type.toBe<Collection.Set<unknown>>();

expect(Collection.Set<string>()).type.toEqual<Collection.Set<string>>();
expect(Collection.Set<string>()).type.toBe<Collection.Set<string>>();
});
10 changes: 4 additions & 6 deletions type-definitions/ts-tests/es6-collections.ts
Expand Up @@ -8,16 +8,14 @@ test('immutable.js collections', () => {
>();
const setImmutable: ImmutableSet<string> = ImmutableSet<string>();

expect(mapImmutable.delete('foo')).type.toEqual<
ImmutableMap<string, number>
>();
expect(setImmutable.delete('bar')).type.toEqual<ImmutableSet<string>>();
expect(mapImmutable.delete('foo')).type.toBe<ImmutableMap<string, number>>();
expect(setImmutable.delete('bar')).type.toBe<ImmutableSet<string>>();
});

test('ES6 collections', () => {
const mapES6: Map<string, number> = new Map<string, number>();
const setES6: Set<string> = new Set<string>();

expect(mapES6.delete('foo')).type.toEqual<boolean>();
expect(setES6.delete('bar')).type.toEqual<boolean>();
expect(mapES6.delete('foo')).type.toBe<boolean>();
expect(setES6.delete('bar')).type.toBe<boolean>();
});

0 comments on commit ed3f2a7

Please sign in to comment.