-1

component.ts

import * as AssetId from "../../../assetid.json";

export class AssetID {
    abc: number;
    xxx: number;
}

export class Sample {
    public assetId: AssetID = AssetId; // Line no : 9
}

assetid.json

{
    "abc": 3,
    "xxx": 4
}

In line # 9 it creates an error like

TS2322: Type 'typeof ".json"' is not assignable to type 'AssetID'. Property 'abc' is missing in type 'typeof ".json"'

I wanted to map this json format to void 'any' type in the typescript code.

venkat
  • 43
  • 9

1 Answers1

1

You should use like this

interface IAssetid {
    abc: number;
    xxx: number;
}

Secondly you should import const from ts file instead of json

export const assetid = {
    'abc': 3,
    'xxx': 4
};

For more info, read this https://stackoverflow.com/a/46991300/3326275

Pratik Joshi
  • 11,485
  • 7
  • 41
  • 73