'How to define class with properties and its data type dynamically in typescript
For e.g. I have following class, with interface ProjectAttrs.
export class ProjectAttrsImpl implements ProjectAttrs {
name: string;
description: string | null;
coordinates: string | null;
}
I have too many classes in JSON implementation so trying to define all classes dynamically. I got following structure from JSON parse
project: {
name: 'string',
description: 'string | null',
coordinates: 'string | null',
}
but its properties like name and description are taking value as string. I want to define its data-type as string not value. Please help
Solution 1:[1]
Parsing from typescript to JSON is not possible, it will not make an interface. A JSON file is just some text with a few primitives, including boolean, number, string and null.
A JSON parser is used from JSON to typescript to generate an interface based on the JSON provided.
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 | temp_user |
