From 2cd4ebffbee70bd2cf551c7a59a19c05fe04e34b Mon Sep 17 00:00:00 2001 From: Sophia Sam Date: Wed, 11 Sep 2024 11:14:09 -0400 Subject: [PATCH 1/3] Fix model.start type for 2-way funcs --- src/Model/fn.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Model/fn.ts b/src/Model/fn.ts index 6d15b9ff..f0d215c5 100644 --- a/src/Model/fn.ts +++ b/src/Model/fn.ts @@ -10,10 +10,10 @@ class NamedFns { } type StartFnParam = unknown; type ModelFn = - (...inputs: Ins) => Out | + ((...inputs: Ins) => Out) | { - get(...inputs: Ins): Out, - set(output: Out, ...inputs: Ins): void, + get(...inputs: Ins): Out; + set(output: Out, ...inputs: Ins): {[key: number] : Ins[number]} | Ins[] | null; }; interface ModelStartOptions { From f09052a4a17b2092c9f60dd6e65478afa45143ac Mon Sep 17 00:00:00 2001 From: Sophia Sam Date: Wed, 11 Sep 2024 11:25:56 -0400 Subject: [PATCH 2/3] Change to commas --- src/Model/fn.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Model/fn.ts b/src/Model/fn.ts index f0d215c5..68a72a32 100644 --- a/src/Model/fn.ts +++ b/src/Model/fn.ts @@ -12,8 +12,8 @@ type StartFnParam = unknown; type ModelFn = ((...inputs: Ins) => Out) | { - get(...inputs: Ins): Out; - set(output: Out, ...inputs: Ins): {[key: number] : Ins[number]} | Ins[] | null; + get(...inputs: Ins): Out, + set(output: Out, ...inputs: Ins): {[key: number] : Ins[number]} | Ins[] | null, }; interface ModelStartOptions { From 55bd241f805e0e4052041ab1d41809f20af62647 Mon Sep 17 00:00:00 2001 From: Eric Hwang Date: Thu, 12 Sep 2024 15:15:39 -0700 Subject: [PATCH 3/3] Further updates to 2-way reactive function set() types - Allow `set()` to return a partial array covering first N inputs to update, and remove extra brackets in `Ins[]` return type since `Ins` is already an array - Individually validate types of each item of of `{ 0: in0, 2: in2, ... }` object return value, instead of using an index signature that allows values to be any of the inputs' types --- src/Model/fn.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Model/fn.ts b/src/Model/fn.ts index 68a72a32..c66ba73d 100644 --- a/src/Model/fn.ts +++ b/src/Model/fn.ts @@ -9,11 +9,20 @@ class NamedFns { } type StartFnParam = unknown; +// From type-fest: https://github.com/sindresorhus/type-fest +type ArrayIndices = + Exclude['length'], Element['length']>; + +type TwoWayReactiveFnSetReturnType = + Partial | + Partial<{ [K in Extract, number>]: Ins[K] }> | + null; + type ModelFn = ((...inputs: Ins) => Out) | { - get(...inputs: Ins): Out, - set(output: Out, ...inputs: Ins): {[key: number] : Ins[number]} | Ins[] | null, + get(...inputs: Ins): Out; + set(output: Out, ...inputs: Ins): TwoWayReactiveFnSetReturnType; }; interface ModelStartOptions { @@ -99,11 +108,7 @@ declare module './Model' { */ fn( name: string, - fn: (...inputs: Ins) => Out | - { - get(...inputs: Ins): Out; - set(output: Out, ...inputs: Ins): void - } + fn: ModelFn ): void; /**