Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate more type tests to TSTyche (#1989)
* chore: migrate type tests to TSTyche * fromJS case * restart ci --------- Co-authored-by: Julien Deniau <1398469+jdeniau@users.noreply.github.com>
- Loading branch information
1 parent
75c9d40
commit bbd8fc9
Showing
8 changed files
with
246 additions
and
170 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
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 |
---|---|---|
@@ -1,49 +1,42 @@ | ||
import { fromJS, List, Map } from 'immutable'; | ||
import { expect, test } from 'tstyche'; | ||
import { fromJS, Collection, List, Map, MapOf } from 'immutable'; | ||
|
||
{ | ||
// fromJS | ||
test('fromJS', () => { | ||
expect(fromJS({}, (a: any, b: any) => b)).type.toEqual< | ||
Collection<unknown, unknown> | ||
>(); | ||
|
||
// $ExpectType Collection<unknown, unknown> | ||
fromJS({}, (a: any, b: any) => b); | ||
expect(fromJS('abc')).type.toBeString(); | ||
|
||
// $ExpectType string | ||
fromJS('abc'); | ||
expect(fromJS([0, 1, 2])).type.toEqual<List<number>>(); | ||
|
||
// $ExpectType List<number> | ||
fromJS([0, 1, 2]); | ||
expect(fromJS(List([0, 1, 2]))).type.toEqual<List<number>>(); | ||
|
||
// $ExpectType List<number> | ||
fromJS(List([0, 1, 2])); | ||
expect(fromJS({ a: 0, b: 1, c: 2 })).type.toEqual< | ||
Map<'b' | 'a' | 'c', number> | ||
>(); | ||
|
||
// $ExpectType Map<"b" | "a" | "c", number> | ||
fromJS({a: 0, b: 1, c: 2}); | ||
expect(fromJS(Map({ a: 0, b: 1, c: 2 }))).type.toEqual< | ||
MapOf<{ a: number; b: number; c: number }> | ||
>(); | ||
|
||
// $ExpectType MapOf<{ a: number; b: number; c: number; }> | ||
fromJS(Map({a: 0, b: 1, c: 2})); | ||
expect(fromJS([{ a: 0 }])).type.toEqual<List<Map<'a', number>>>(); | ||
|
||
// $ExpectType List<Map<"a", number>> | ||
fromJS([{a: 0}]); | ||
expect(fromJS({ a: [0] })).type.toEqual<Map<'a', List<number>>>(); | ||
|
||
// $ExpectType Map<"a", List<number>> | ||
fromJS({a: [0]}); | ||
expect(fromJS([[[0]]])).type.toEqual<List<List<List<number>>>>(); | ||
|
||
// $ExpectType List<List<List<number>>> | ||
fromJS([[[0]]]); | ||
|
||
// $ExpectType Map<"a", Map<"b", Map<"c", number>>> | ||
fromJS({a: {b: {c: 0}}}); | ||
} | ||
|
||
{ | ||
// fromJS in an array of function | ||
expect(fromJS({ a: { b: { c: 0 } } })).type.toEqual< | ||
Map<'a', Map<'b', Map<'c', number>>> | ||
>(); | ||
}); | ||
|
||
test('fromJS in an array of function', () => { | ||
const create = [(data: any) => data, fromJS][1]; | ||
|
||
// $ExpectType any | ||
create({ a: 'A' }); | ||
expect(create({ a: 'A' })).type.toBeAny(); | ||
|
||
const createConst = ([(data: any) => data, fromJS] as const)[1]; | ||
|
||
// $ExpectType Map<"a", string> | ||
createConst({ a: 'A' }); | ||
} | ||
expect(createConst({ a: 'A' })).type.toEqual<Map<'a', string>>(); | ||
}); |
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 |
---|---|---|
@@ -1,84 +1,63 @@ | ||
import { | ||
get, | ||
has, | ||
set, | ||
remove, | ||
update, | ||
} from 'immutable'; | ||
import { expect, test } from 'tstyche'; | ||
import { get, has, set, remove, update } from 'immutable'; | ||
|
||
{ | ||
// get | ||
test('get', () => { | ||
expect(get([1, 2, 3], 0)).type.toEqual<number | undefined>(); | ||
|
||
// $ExpectType number | undefined | ||
get([1, 2, 3], 0); | ||
expect(get([1, 2, 3], 0, 'a')).type.toEqual<number | 'a'>(); | ||
|
||
// $ExpectType number | "a" | ||
get([1, 2, 3], 0, 'a'); | ||
expect(get({ x: 10, y: 20 }, 'x')).type.toEqual<number | undefined>(); | ||
|
||
// $ExpectType number | undefined | ||
get({ x: 10, y: 20 }, 'x'); | ||
expect(get({ x: 10, y: 20 }, 'z', 'missing')).type.toEqual< | ||
number | 'missing' | ||
>(); | ||
}); | ||
|
||
// $ExpectType number | "missing" | ||
get({ x: 10, y: 20 }, 'z', 'missing'); | ||
} | ||
test('has', () => { | ||
expect(has([1, 2, 3], 0)).type.toBeBoolean(); | ||
|
||
{ | ||
// has | ||
expect(has({ x: 10, y: 20 }, 'x')).type.toBeBoolean(); | ||
}); | ||
|
||
// $ExpectType boolean | ||
has([1, 2, 3], 0); | ||
test('set', () => { | ||
expect(set([1, 2, 3], 0, 10)).type.toEqual<number[]>(); | ||
|
||
// $ExpectType boolean | ||
has({ x: 10, y: 20 }, 'x'); | ||
} | ||
expect(set([1, 2, 3], 0, 'a')).type.toRaiseError(); | ||
|
||
{ | ||
// set | ||
expect(set([1, 2, 3], 'a', 0)).type.toRaiseError(); | ||
|
||
// $ExpectType number[] | ||
set([1, 2, 3], 0, 10); | ||
expect(set({ x: 10, y: 20 }, 'x', 100)).type.toEqual<{ | ||
x: number; | ||
y: number; | ||
}>(); | ||
|
||
// $ExpectError | ||
set([1, 2, 3], 0, 'a'); | ||
expect(set({ x: 10, y: 20 }, 'x', 'a')).type.toRaiseError(); | ||
}); | ||
|
||
// $ExpectError | ||
set([1, 2, 3], 'a', 0); | ||
test('remove', () => { | ||
expect(remove([1, 2, 3], 0)).type.toEqual<number[]>(); | ||
|
||
// $ExpectType { x: number; y: number; } | ||
set({ x: 10, y: 20 }, 'x', 100); | ||
expect(remove({ x: 10, y: 20 }, 'x')).type.toEqual<{ | ||
x: number; | ||
y: number; | ||
}>(); | ||
}); | ||
|
||
// $ExpectError | ||
set({ x: 10, y: 20 }, 'x', 'a'); | ||
} | ||
test('update', () => { | ||
expect(update([1, 2, 3], 0, (v: number) => v + 1)).type.toEqual<number[]>(); | ||
|
||
{ | ||
// remove | ||
expect(update([1, 2, 3], 0, 1)).type.toRaiseError(); | ||
|
||
// $ExpectType number[] | ||
remove([1, 2, 3], 0); | ||
expect(update([1, 2, 3], 0, (v: string) => v + 'a')).type.toRaiseError(); | ||
|
||
// $ExpectType { x: number; y: number; } | ||
remove({ x: 10, y: 20 }, 'x'); | ||
} | ||
expect(update([1, 2, 3], 'a', (v: number) => v + 1)).type.toRaiseError(); | ||
|
||
{ | ||
// update | ||
expect(update({ x: 10, y: 20 }, 'x', (v: number) => v + 1)).type.toEqual<{ | ||
x: number; | ||
y: number; | ||
}>(); | ||
|
||
// $ExpectType number[] | ||
update([1, 2, 3], 0, (v: number) => v + 1); | ||
|
||
// $ExpectError | ||
update([1, 2, 3], 0, 1); | ||
|
||
// $ExpectError | ||
update([1, 2, 3], 0, (v: string) => v + 'a'); | ||
|
||
// $ExpectError | ||
update([1, 2, 3], 'a', (v: number) => v + 1); | ||
|
||
// $ExpectType { x: number; y: number; } | ||
update({ x: 10, y: 20 }, 'x', (v: number) => v + 1); | ||
|
||
// $ExpectError | ||
update({ x: 10, y: 20 }, 'x', (v: string) => v + 'a'); | ||
} | ||
expect( | ||
update({ x: 10, y: 20 }, 'x', (v: string) => v + 'a') | ||
).type.toRaiseError(); | ||
}); |
Oops, something went wrong.