Angular HTMLCollectionOf在类型'中缺少以下属性;节点列表';

Angular HTMLCollectionOf在类型'中缺少以下属性;节点列表';,angular,typescript,stenciljs,stencil-component,Angular,Typescript,Stenciljs,Stencil Component,我刚从模具0更新到1,在生成组件集合后出现此错误 [ ERROR ] TypeScript: ./src\components\layout\tabs\aep-tabs.tsx:24:5 Type 'HTMLCollectionOf<Element>' is missing the following properties from type 'NodeList': forEach, entries, keys, values L23: addTi

我刚从模具0更新到1,在生成组件集合后出现此错误

[ ERROR ]  TypeScript: ./src\components\layout\tabs\aep-tabs.tsx:24:5
       Type 'HTMLCollectionOf<Element>' is missing the following properties from type 'NodeList': forEach, entries,
       keys, values

 L23:  addTitleEvents() {
 L24:    this.tabTitleElements = this.tabs.getElementsByClassName('tab-title');
 L25:    [].forEach.call(this.tabTitleElements, (tab, pos) => {...
节点版本:10 TSC版本:3.6.3

我更新了“lib”、“target”,还将节点列表转换为数组,但它们都不起作用。有人知道我如何解决这个问题吗

  • 方法返回

  • 方法返回

您应该将代码从
getElementsByClassName
替换为
querySelectorAll

//this.tabTitleElements=this.tabs.getElementsByClassName('tab-title');//改变这个
this.tabTitleElements=this.tabs.querySelectorAll(“.tab title”);
import { Component, h, Listen, Element, State, Event, Method, EventEmitter } from '@stencil/core';

@Component({
  tag: 'aep-tabs',
  styleUrl: 'aep-tabs-style.scss'
})
export class AepTabs {
  @Element() tabs: HTMLElement;
  @State() initIndex: number = 0;
  @Event() tabClick: EventEmitter;
  private tabsElements;
  private tabsElementList: Array<any> = [];
  private tabTitleElements: NodeList; // <---- HERE

  componentWillLoad() {
    this.createTabsTitles(this.tabs.querySelectorAll('aep-tab'));
  }

  componentDidLoad() {
    this.addTitleEvents();
  }

  addTitleEvents() {

    // ERROR HERE 'this.tabTitleElements' is displaying the error message.
    this.tabTitleElements = this.tabs.getElementsByClassName('tab-title');
    [].forEach.call(this.tabTitleElements, (tab, pos) => {
      tab.addEventListener('click', () => {
        this.tabClick.emit(tab);
        this.activeTabs(pos);
      });
    });
    this.activeTabs(this.initIndex);
  }

  createTabsTitles(tabsList: NodeList) {
    this.tabsElements = tabsList;
    [].forEach.call(this.tabsElements, tab => {
      this.tabsElementList.push(
        <div class="tab-title" data-automation={tab.titletab.toString().toLowerCase()}>
          <span>{tab.titletab}</span>
        </div>
      );
    });
  }
  @Method()
  async activeTabs(index: number) {
    // ERROR HERE 'this.tabTitleElements' is displaying the error message
    this.tabTitleElements = this.tabs.getElementsByClassName('tab-title');
    [].forEach.call(this.tabTitleElements, (tab, pos) => {
      if (index === pos) {
        tab.classList.add('active');
        tab.classList.remove('inactive');
      } else {
        tab.classList.remove('active');
        tab.classList.add('inactive');
      }
    });

    [].forEach.call(this.tabsElements, (tab, pos) => {
      if (index === pos) {
        tab.classList.add('active');
        tab.classList.remove('inactive');
      } else {
        tab.classList.remove('active');
        tab.classList.add('inactive');
      }
    });
  }

  @Listen('clicktab')
  clicktabHandler(event: CustomEvent) {
    this.activeTabs(event.detail);
  }

  render() {
    return (
      <div class="aep-tabs">
        <nav>{this.tabsElementList}</nav>
        <div class="tab-container" data-automation="tab-container">
          <div class="tab-content">
            <slot />
          </div>
        </div>
      </div>
    );
  }
}
{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "allowUnreachableCode": false,
    "declaration": false,
    "experimentalDecorators": true,
    "allowJs": true,
    "lib": ["dom", "es7", "dom.iterable"],
    "moduleResolution": "node",
    "module": "esnext",
    "target": "es2017",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "jsx": "react",
    "jsxFactory": "h"
  },
  "include": ["src", "types/jsx.d.ts"],
  "exclude": ["node_modules"]
}