A list of people in TypeScript
Du skriver inn
- Språk
- TypeScript
- Rottypenavn
- Person
- JSON
- [{"name":null,"score":9.5,"tags":["new","returning"]},{"name":"Ada","active":true,"tags":[]}]
Du får
- Kode
- // The JSON root is an array; each item matches this interface. export interface Person { name: string | null; score?: number; tags: Array<string>; active?: boolean; }
Name is null in one item and a string in the other, so it becomes string | null. Score and active appear in only one item each, so they are marked optional with a question mark. Tags is a list of strings in both.
Kjørt med verktøyets egen kode.