-
Notifications
You must be signed in to change notification settings - Fork 11
Description
example code:
import { $bind } from "@sp2/updater";
type Hoge = {
fuga: {
key1: string;
key2: string;
};
};
const { $push, $path } = $bind<Hoge>();
$push($path("fuga", "key1"), "hoge"); // valid
const key = Math.random() > 0.5 ? "key1" : "key2";
$push($path("fuga", key), "hoge"); // $path is type errorI see here.
https://github.com/phenyl-js/sp2/blob/5c14b6d31cf228b8403c2f184787eb02cbe41c80/modules/format/src/common/bound-document-path.ts#L21-L28
https://github.com/phenyl-js/sp2/blob/5c14b6d31cf228b8403c2f184787eb02cbe41c80/modules/format/src/common/bound-document-path.ts#L151-L154
The $path method is generating some depth path type and this using like following codes.
K1 extends keyof T, K2 extends keyof T[K1] ...
However if type K[i] had union type value, looks like TS compiler is checking 'left side value can extends all of expanded union type value?'.
And i think this issue can be solved by using like following codes.
K1 extends Extract<K1, keyof T>, K2 extends Extract<K2, T[K1]> ...
But if resolved this issue, #37 Error is still showing...