0

I am trying to retrieve all the terms for a term-set in my term store to be used in an SPFx web part.

Following the guide given here.

// get terms merged with data from a term set
const terms4: (ITerm & ITermData)[] = store.getTermSetById("0ba6845c-1468-4ec5-a5a8-718f1fb05431").terms.get();

This line is failing due:

Type 'Promise<(ITermData & ITerm)[]>' is missing the following properties from type '(ITerm & ITermData)[]': length, pop, push, concat, and 16 more.ts(2740)

Any idea how to fix that?

Full code:

  public componentDidMount() {
    this.getTerms();
  }

  public async getTerms() {
    const store: ITermStore = await taxonomy.termStores.getByName("Taxonomy_O1cHqzMmDZNz4UeaKJLVpA==");

    const labelMatchInfo: ILabelMatchInfo = {
        TermLabel: "My Label",
        TrimUnavailable: true,
    };

    const terms: ITerms = store.getTerms(labelMatchInfo);

    // get term instances merged with data
    const terms2: (ITermData & ITerm)[] = await store.getTerms(labelMatchInfo).get();

    const terms3: ITerms = store.getTermSetById("6a488843-cebc-47b7-8606-e4e165e6fceb").terms;

    // get terms merged with data from a term set
    const terms4: (ITerm & ITermData)[] = store.getTermSetById("0ba6845c-1468-4ec5-a5a8-718f1fb05431").terms.get();
}

1 Answer 1

3

Adding await fixed it! (microsoft should update the docs)

Fix:

// get terms merged with data from a term set
const terms4: (ITerm & ITermData)[] = await store.getTermSetById("0ba6845c-1468-4ec5-a5a8-718f1fb05431").terms.get();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.