Skip to content

Commit 6a85798

Browse files
authored
Merge pull request #351 from busy-dog/feat/filter-unknown-type
feat: 优化FilterUnknownType工具类
2 parents 8a4dc47 + 66649c0 commit 6a85798

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

test/component.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,3 +505,4 @@ Component<{}, {}, { fn(): void }, []>({
505505
}
506506
})
507507
}
508+

test/issue.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,4 +634,25 @@ import WX = WechatMiniprogram
634634
},
635635
}
636636
})
637+
}
638+
639+
// https://github.com/wechat-miniprogram/api-typings/pull/351
640+
{
641+
type Properties = {
642+
customProp: string
643+
[key: string]: unknown;
644+
[key: number]: string;
645+
}
646+
Component<Properties, {}, {}, []>({
647+
lifetimes: {
648+
created() {
649+
this.properties[1] = '1';
650+
expectError(() => {
651+
this.properties[2] = 2;
652+
});
653+
expectError(this.properties.xxx);
654+
this.properties.customProp = 'customProp';
655+
}
656+
}
657+
})
637658
}

types/wx/lib.wx.component.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ SOFTWARE.
2121
***************************************************************************** */
2222

2323
declare namespace WechatMiniprogram.Component {
24-
type FilterUnknownType<T> = string extends keyof T ? {} : T
24+
type FilterUnknownType<T> = {
25+
[P in keyof T as string extends P ? never : P]: T[P]
26+
}
2527
type Instance<
2628
TData extends DataOption,
2729
TProperty extends PropertyOption,

0 commit comments

Comments
 (0)