Samantha J T Star
Samantha J T Star

Reputation: 32848

How can I declare an array of an interface as a Typescript function parameter?

I declared the following:

ExamTypeId = {
    All: {
        id: this.examTypeSelectId,
        text: 'Exam Type: All',
        val: 0
    }
}

and an interface:

export interface IEnumElement {
    id: string;
    text: string;
    val: number
}

A function that I call:

checkGrid(expectedCount: number, row: string, params: IEnumElement[]) {
    ...
    ...
}

Now I am trying to call my function like this:

page.checkGrid(4, page.gridRow,  [page.ExamStatusId.All, page.ExamTypeId.All]);

It is giving me a java exception error which I think is related to the way I am calling the function. Can someone confirm if this is the correct way to set the type for an array of IEnumElement?

Upvotes: 0

Views: 159

Answers (1)

Fenton
Fenton

Reputation: 251262

In the code you have supplied, you have used:

page.ExamStatusId.All

But ExamStatusId isn't defined anywhere... did you mean to use ExamTypeId?

In any case, if there is an ExamStatusId property, it would also have to contain an All element that has the same structure as IEnumElement.

If the error is at runtime, make sure you have included all of the JavaScript files at runtime (all the files, all with a .js extension and in the right order!)

If you are still stuck, can you share the error message?

Upvotes: 1

Related Questions