export type PropType = T extends Array<(infer U)> ? IArrayProp : IObjectProp class PropertyNameProvider implements IObjectProp, IArrayProp, IPathResolve { private parts: string[] = [] prop>(key: K): PropType { this.parts.push(key) return this as any as PropType } index(index: number): PropType { this.parts.push(`${index}`) return this as any as PropType; } resolve() { return this.parts.join(".") } } export interface IPathResolve { resolve(): string } export interface IObjectProp { prop>(key: K): PropType } export interface IArrayProp { index(index: number): PropType } export type PropertyPathFor = (builder: PropType) => IObjectProp | IArrayProp export class PropertyPath { static for(b: PropertyPathFor): string { const a = b(new PropertyNameProvider() as any) return (a as any as IPathResolve).resolve() } } export type FormBinderKey = Extract | PropertyPathFor function toString(param: FormBinderKey) { if (typeof param === "string") { return param } return PropertyPath.for(param) } export function toDataPath(param: FormBinderKey, parentPath?: string) { if (param === undefined) { return } return parentPath ? `${parentPath}.${toString(param)}` : toString(param) }