'Type is missing the following properties from type

I have the following interface in a typescript file.

export interface TempContext {
  FriendlyName?: boolean;
  hList: SelectFilterListItem[];
}

SelectFilterListItem is an interface in another file

export interface SelectFilterListItem {
  name: string;
  value: any;
}

I then want to use this in a function in the same file

filterDef: new SelectFilterDef({
        filterList: (context: TempContext) => context.hList,
      }),

I get the following error

Type '(context: TempContext) => SelectFilterListItem[]' is missing the following properties from type 'SelectFilterListItem[]': pop, push, concat, join, and 25 more.



Solution 1:[1]

According to me as your hList is not optional, you have to provide value of type SelectFilterListItem to context.hList as hList is of type SelectFilterListItem[] i.e. array of objects

hence your filterDef will get changed to

    filterDef: new SelectFilterDef({
               filterList: (context: TempContext) => {
               context.hList = [{name: 'Test1',value: 'val1'},{name: 'Test2',value: 'val2'}]
               }
            })

Solution 2:[2]

import file of SelectFilterListItem in TempContext file like this.

import {SelectFilterListItem} from "some path";

then it will work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nirali
Solution 2 Farhat Zaman