gpt4 book ai didi

typescript - 未捕获的类型错误 : Cannot read property 'release' of undefined

转载 作者:搜寻专家 更新时间:2023-10-30 21:59:05 25 4
gpt4 key购买 nike

大家好!

我需要一些帮助。我想用特定结构测试我的服务树。

我的测试看起来像:

describe(`Service selector`, () => {
describe(`getCurrentServiceTree`, () => {
it(`should build the generic service tree`, () => {
const services = [
'{http://namespace-example.fr/service/technique/version/1.0}Localpart0',
'{http://namespace-example.fr/service/technique/version/1.0}Localpart1',
'{http://namespace-example.fr/service/technique/version/2.0}Localpart2',
'{http://namespace-example.fr/service/technique/version/3.0}Localpart3',
'{http://namespace-example.fr/service/technique/version/3.0}Localpart4',
];

const expectedTree: TreeElement<any>[] = [
{
name: 'http://namespace-example.fr/service/technique/version/1.0',
children: [
{
name: 'Localpart0',
children: [],
isFolded: false,
cssClass: 'item-localpart',
},
{
name: 'Localpart1',
children: [],
isFolded: false,
cssClass: 'item-localpart',
},
],
isFolded: false,
cssClass: 'item-namespace',
},
{
name: 'http://namespace-example.fr/service/technique/version/2.0',
children: [
{
name: 'Localpart2',
children: [],
isFolded: false,
cssClass: 'item-localpart',
},
],
isFolded: false,
cssClass: 'item-namespace',
},
{
name: 'http://namespace-example.fr/service/technique/version/3.0',
children: [
{
name: 'Localpart3',
children: [],
isFolded: false,
cssClass: 'item-localpart',
},
{
name: 'Localpart4',
children: [],
isFolded: false,
cssClass: 'item-localpart',
},
],
isFolded: false,
cssClass: 'item-namespace',
},
];

const generatedStore: Partial<IStore> = {
services: {
byId: services.reduce(
(acc, name, index) => ({ ...acc, [`service${index}`]: { name } }),
{}
),
allIds: services.map((_, index) => `service${index}`),
isFetchingServices: false,
selectedServiceId: '',
},
};

expect(getCurrentServiceTree(generatedStore as any)).toEqual(
expectedTree
);
});
});
});

我不知道这是 TypeScript 问题还是与 RxJS 相关.. 或者只是我的代码 :(

当我将鼠标放在 getCurrentServiceTree 上时,我得到了:

(alias) getCurrentServiceTree(state: IStore): TreeElement[] import getCurrentServiceTree

不知道我用对了没有Partial<T> .
我无法将 generatedStore 键入为 ..
当我将鼠标放在 上时,我有:

[ts] L'argument de type '() => any' n'est pas attribuable au paramètre de type 'IStore'. La propriété 'ui' est manquante dans le type '() => any'.

export const getCurrentServiceTree = createSelector(
getSelectedWorkspaceId,
getServicesAllIds,
getServicesById,
(selectedWorkspaceId, servicesAllIds, servicesByIds): TreeElement<any>[] => {
const baseUrl = `/workspaces/${selectedWorkspaceId}/services`;

const servicesWithNspLocalpart = servicesAllIds.map(id => ({
...findNamespaceLocalpart(servicesByIds[id].name),
id,
}));

const groupedByNamespace = groupByNamespace(servicesWithNspLocalpart);

return groupedByNamespace.map(nspWithLocalparts => ({
name: nspWithLocalparts.namespace,
isFolded: false,
cssClass: `item-namespace`,
link: ``,
children: nspWithLocalparts.localparts.map(localpart => ({
name: localpart.name,
isFolded: false,
cssClass: `item-localpart`,
link: `${baseUrl}/${localpart.id}`,
children: [],
})),
}));
}
);

我应该做什么?
有人可以向我解释如何解决我的问题吗?

最佳答案

我今天遇到了完全相同的错误。

一开始并不清楚错误是从哪里来的。

我为调试所做的工作:

  • 而不是使用 ng test 运行测试(也可能是 headless 的),不要使用 headless 模式并使用参数 --no-sourcemaps 启动它们

  • 我在浏览器中收到(稍微)更好的消息,至少告诉我是哪个文件导致了问题

  • 即使从那里,也不清楚问题到底出在哪里,我想通了 ng test不报告循环依赖但 ng serve

  • 从那里很容易找到导致循环依赖的函数,我只需要将它移到另一个文件中(无论如何这更有意义)

关于typescript - 未捕获的类型错误 : Cannot read property 'release' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48154330/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com