首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >未定义TypeError:无法读取未定义属性的“释放”

未定义TypeError:无法读取未定义属性的“释放”
EN

Stack Overflow用户
提问于 2018-01-08 16:30:26
回答 1查看 1.6K关注 0票数 2

嗨伙计们!

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

我的测试看起来是:

代码语言:javascript
运行
复制
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上时,我得到了这样的信息:

(别名) getCurrentServiceTree (状态: IStore):TreeElement[] import getCurrentServiceTree

我不知道我是否正确使用了Partial<T>

我不能把generatedStore打成..。

当我把鼠标放进去的时候,我有:

=>任何‘n’- pas可归因于au paramètre de type 'IStore‘。La propriété'ui‘est manquante dans le type '() => any’

代码语言:javascript
运行
复制
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: [],
      })),
    }));
  }
);

我该怎么做?

有人能解释一下我怎么解决我的问题吗?

EN

回答 1

Stack Overflow用户

发布于 2018-05-10 12:03:50

我今天也遇到了同样的错误。

现在还不清楚这个错误是从哪里来的。

我为调试所做的工作:

  • 不要使用ng test (也可能是无头测试)运行您的测试,不要使用无头模式,也不要使用参数--no-sourcemaps启动它们。
  • 我在浏览器中有一条(稍微)更好的消息,至少告诉我是哪个文件导致了问题。
  • 即使在那里,问题的确切位置也不明显,我发现ng test不报告循环dep,但ng serve报告。
  • 从那时起,它相当容易找到导致循环依赖的函数,我只需将它移到另一个文件中(这是更有意义的)。
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48154330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档