Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dai-shi authored Apr 21, 2024
2 parents c6892e6 + b47a029 commit 5fa1d9c
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions __tests__/02_type.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { TypeEqual } from 'ts-expect';

import { createSlice, withSlices } from '../src/index';

describe('type spec', () => {
describe('slice type', () => {
it('single slice', () => {
const countSlice = createSlice({
name: 'count',
Expand All @@ -25,8 +25,10 @@ describe('type spec', () => {
>
>(true);
});
});

it('detect name collisions', () => {
describe('name collisions', () => {
it('same slice names', () => {
const countSlice = createSlice({
name: 'count',
value: 0,
Expand All @@ -44,7 +46,7 @@ describe('type spec', () => {
expectType<never>(withSlices(countSlice, anotherCountSlice));
});

it('detect name collisions with actions', () => {
it('slice name and action name', () => {
const countSlice = createSlice({
name: 'count',
value: 0,
Expand All @@ -62,7 +64,28 @@ describe('type spec', () => {
expectType<never>(withSlices(countSlice, anotherCountSlice));
});

it('detect args collisions', () => {
it('slice name and action name (overlapping case)', () => {
const countSlice = createSlice({
name: 'count',
value: 0,
actions: {
inc: () => (prev) => prev + 1,
},
});
const anotherCountSlice = createSlice({
name: 'anotherCount',
value: 0,
actions: {
count: () => (prev) => prev + 1,
dec: () => (prev) => prev - 1,
},
});
expectType<never>(withSlices(countSlice, anotherCountSlice));

Check failure on line 83 in __tests__/02_type.spec.tsx

View workflow job for this annotation

GitHub Actions / test

Argument of type '(set: (fn: (prevState: { count: number; } & { inc: () => void; } & { anotherCount: number; } & { count: () => void; dec: () => void; }) => Partial<{ count: number; } & { inc: () => void; } & { anotherCount: number; } & { ...; }>) => void) => { ...; } & ... 2 more ... & { ...; }' is not assignable to parameter of type 'never'.
});
});

describe('args collisions', () => {
it('different args', () => {
const countSlice = createSlice({
name: 'count',
value: 0,
Expand All @@ -81,7 +104,7 @@ describe('type spec', () => {
expectType<never>(withSlices(anotherCountSlice, countSlice));
});

it('no args collisions', () => {
it('same args', () => {
const countSlice = createSlice({
name: 'count',
value: 0,
Expand All @@ -104,7 +127,7 @@ describe('type spec', () => {
);
});

it('detect args collisions (overload case)', () => {
it('overload case', () => {
const countSlice = createSlice({
name: 'count',
value: 0,
Expand Down

0 comments on commit 5fa1d9c

Please sign in to comment.