diff --git a/packages/typeless-form/package.json b/packages/typeless-form/package.json index 87c6f81..120aaf3 100644 --- a/packages/typeless-form/package.json +++ b/packages/typeless-form/package.json @@ -67,7 +67,7 @@ "rimraf": "^3.0.2", "rxjs": "^6.3.3", "tslint": "6.0.0", - "typescript": "3.8.2" + "typescript": "^3.9.6" }, "resolutions": { "@types/react": "^16.8.12" diff --git a/packages/typeless-router/package.json b/packages/typeless-router/package.json index 05be25c..3c2fc9f 100644 --- a/packages/typeless-router/package.json +++ b/packages/typeless-router/package.json @@ -67,7 +67,7 @@ "rimraf": "^3.0.2", "rxjs": "^6.3.3", "tslint": "6.0.0", - "typescript": "3.8.2" + "typescript": "^3.9.6" }, "resolutions": { "@types/react": "^16.8.12" diff --git a/packages/typeless/__tests__/type/Epic.test.ts b/packages/typeless/__tests__/type/Epic.test.ts new file mode 100644 index 0000000..edc33a3 --- /dev/null +++ b/packages/typeless/__tests__/type/Epic.test.ts @@ -0,0 +1,42 @@ +import { createModule, ActionMap } from '../../src/createModule'; +import { Epic } from '../../src/Epic'; +import { TT } from './TypeTester'; + +function createAction(acts: T) { + return createModule(Symbol('test')).withActions(acts)[1]; +} +TT.describe('onMany', () => { + const m1 = createAction({ foo: (num: number) => ({ payload: { num } }) }); + const m2 = createAction({ foo: (boo: boolean) => ({ payload: { boo } }) }); + const m3 = createAction({ foo: () => ({ payload: 'bar' }) }); + const m4 = createAction({ foo: () => ({ payload: Symbol('baz') }) }); + const m5 = createAction({ foo: (str: string) => ({ payload: { str } }) }); + const m6 = createAction({ foo: () => ({ payload: ['array'] }) }); + + TT.describe('should error called with', () => { + TT.it('empty array', () => { + // @ts-expect-error + new Epic().onMany([], () => null); + }); + TT.it('has 1 item array', () => { + // @ts-expect-error + new Epic().onMany([m1.foo], () => null); + }); + }); + TT.describe("should infer callback's arguments", () => { + TT.it('called with many arguments', () => { + new Epic().onMany([m1.foo, m2.foo, m3.foo, m4.foo, m5.foo, m6.foo], p => { + type Expected = + | { num: number } + | { boo: boolean } + | string + | symbol + | { str: string } + | string[]; + TT.assert>(); + + return null; + }); + }); + }); +}); diff --git a/packages/typeless/__tests__/type/useMappedState.test.ts b/packages/typeless/__tests__/type/useMappedState.test.ts index 76578e4..41a95a8 100644 --- a/packages/typeless/__tests__/type/useMappedState.test.ts +++ b/packages/typeless/__tests__/type/useMappedState.test.ts @@ -10,6 +10,10 @@ TT.describe('useMappedState', () => { const getCountState = createTestModule<{ count: number }>(); const getTextState = createTestModule<{ text: string }>(); + TT.it('should error with empty array', () => { + // @ts-expect-error + useMappedState([], () => null); + }); TT.it("should infer callback's arguments type", () => { useMappedState([getCountState, getTextState], (c, t) => { TT.assert>(); diff --git a/packages/typeless/package.json b/packages/typeless/package.json index 88f7014..d6364dc 100644 --- a/packages/typeless/package.json +++ b/packages/typeless/package.json @@ -69,7 +69,7 @@ "shallow-equal": "^1.2.1", "ts-jest": "^25.5.0", "tslint": "6.0.0", - "typescript": "3.8.2" + "typescript": "^3.9.6" }, "peerDependencies": { "react": "^16.8.2", diff --git a/packages/typeless/src/Epic.ts b/packages/typeless/src/Epic.ts index 6d56a84..ff64e90 100644 --- a/packages/typeless/src/Epic.ts +++ b/packages/typeless/src/Epic.ts @@ -43,29 +43,7 @@ export class Epic { on(ac: TAC, handler: EpicHandler) { return this.add(ac, handler); } - onMany( - ac: [TAC, TAC2], - handler: EpicHandler - ): this; - onMany( - ac: [TAC, TAC2, TAC3], - handler: EpicHandler - ): this; - onMany( - ac: [TAC, TAC2, TAC3, TAC4], - handler: EpicHandler - ): this; - onMany< - TAC extends AC, - TAC2 extends AC, - TAC3 extends AC, - TAC4 extends AC, - TAC5 extends AC - >( - ac: [TAC, TAC2, TAC3, TAC4, TAC5], - handler: EpicHandler - ): this; - onMany(ac: AC[], handler: EpicHandler) { + onMany(ac: T, handler: EpicHandler) { return this.add(ac, handler); } diff --git a/packages/typeless/src/types.ts b/packages/typeless/src/types.ts index fefd1c6..e1de918 100644 --- a/packages/typeless/src/types.ts +++ b/packages/typeless/src/types.ts @@ -31,6 +31,6 @@ export interface StateGetter { useState(): T; } -export type TupleOfStateGetter = [] | [StateGetter, ...StateGetter[]]; +export type TupleOfStateGetter = [StateGetter, ...StateGetter[]]; export type EqualityFn = (a: T, b: T) => boolean; diff --git a/yarn.lock b/yarn.lock index 52f48de..b8e80f9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7570,10 +7570,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@3.8.2: - version "3.8.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.2.tgz#91d6868aaead7da74f493c553aeff76c0c0b1d5a" - integrity sha512-EgOVgL/4xfVrCMbhYKUQTdF37SQn4Iw73H5BgCrF1Abdun7Kwy/QZsE/ssAy0y4LxBbvua3PIbFsbRczWWnDdQ== +typescript@^3.9.6: + version "3.9.6" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a" + integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw== uglify-js@^3.1.4: version "3.8.0"