Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"'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;
like image 409
David Lin Avatar asked Nov 19 '18 18:11

David Lin


2 Answers

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

like image 199
T.J. Crowder Avatar answered Oct 19 '22 19:10

T.J. Crowder


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;
like image 23
Rod Astrada Avatar answered Oct 19 '22 20:10

Rod Astrada