要創建 JSON 檔案,我使用的是 C# 字典:
public Dictionary<int, List<string>> AbsatzNrSaetzeText { get; set; } = new Dictionary<int, List<string>>();
這將導致Sound .json,我正在嘗試使用http://json2ts.com/將其轉換為 TypeScript 資料結構。
這將導致這樣的事情:
declare module namespace {
export interface AbsatzNrSaetzeText {
2: string[];
3: string[];
4: string[];
5: string[];
6: string[];
8: string[];
9: string[];
10: string[];
11: string[];
//...
但這看起來不是很聰明,因為對于每個AbsatzNrSaetzeTextorAbsatzNrSaetzeTextPunkte條目,都使用了鍵(來自字典)。最后,資料結構看起來會很大,令人困惑和雜亂無章。
是否有另一種解決方案(請提供代碼片段)在打字稿中創建資料結構?
uj5u.com熱心網友回復:
TypeScript 已經有一個Record<K, V>你可以Record<number, string[]>在這種情況下使用的型別。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/407775.html
標籤:
