David Lin
David Lin

Reputation: 133

"'Output' only refers to a type, but is being used a value here" error

My object instantiation using a constructor declared for the interface:

let obj = new Output(cur.req, cur.type, cur.batchId, cur.rowId, dat2);

Model data structure

import { Data } from './data';

export interface Output {
 req: string;
 type: string;
 batchId: number;
 rowId: number;
 data: Array<Data>
}

export interface OutputConstructor {
 new (req: number, type: string, batchId: number, rowId: number, data:Array<Data>): Output;
 Clone(): Output;
}

export var Output: OutputConstructor;

Upvotes: 7

Views: 26886

Answers (2)

Rod Astrada
Rod Astrada

Reputation: 479

Like another user said before, Output is an interface. So what you have to do to set the type is this:

let obj = {} as Output;

Upvotes: 11

T.J. Crowder
T.J. Crowder

Reputation: 1074485

Output is an interface, not a class. You can't directly instantiate an interface.

Upvotes: 19

Related Questions