
不知道怎么豪

获得徽章 0
来位 ts 的大佬帮我指导一下这个问题呗。
type AAA = {
a: string;
b: number;
};
type BBB = {
[key in keyof AAA]?: AAA[key][];
};
const bbb: BBB = {};
const aaa: AAA = { a: "aaaa", b: 123 };
ccc("a", aaa);
function ccc<K extends keyof BBB>(key: K, aaa: AAA) {
bbb[key] = bbb[key] || [];
const bk = bbb[key];
const aa = aaa[key];
// 类型“string | number”的参数不能赋给类型“never”的参数。
// 不能将类型“string”分配给类型“never”。 ts(2345)
bk?.push(aa);
}
怎么改最后一行代码都会提示 ts(2345) 的错误
哪位typescript大佬帮我看看这个问题呗,我应该怎么弄呀:
在注释的下一行代码会提示注释的错误,应该怎么写这个代码呀。
这是代码
```
const funcs = {
a: function (a: string, b: string) {
return a + b;
},
c: function (a: number, b: number) {
return a + b;
},
};
type FuncsType = typeof funcs;
function mapFunc<K extends keyof FuncsType>(name: K, ...params: Parameters<FuncsType[K]>): ReturnType<FuncsType[K]> {
// 扩张参数必须具有元组类型或传递给 rest 参数。ts(2556)
return funcs[name](...params);
}
var aa = mapFunc("a", "cc", "bbb");
``` xdm,有个问题咨询一下,有哪位typescript的大佬帮忙看看啊,琢磨好久了,一直没发解决:
很老的项目用iframe开发,在顶层html里面定义了很多公用方法,在下级的html里面通过top.xxx 的方式调用,我现在想要接入ts希望能够增加vscode的智能提示,现在想要对top的属性进行扩展,但是在ts的lib.dom.d.ts里面已经定义过top了,我这儿再次扩展会提示ts(2403)的错误,有没有大佬帮我看看呀。
想要实现以下代码类似的效果:
interface TopWindow extends Window {
createMP: (key?: string) => CustomPlayer;
}
declare var top: TopWindow | null;
但是最后一行提示错误
Subsequent variable declarations must have the same type. Variable 'top' must be of type 'Window | null', but here has type 'TopWindow | null'.ts(2403) xdm,有些不错的内容想分享在团队里面,但是又担心别人说内卷竞争。这咋搞啊