typescript - Dart'ta bir harita türünün şeklini nasıl tanımlanır
Typescript'te:
const someMap = {a: "hi", b: 3}; // TS can understand the type of someMap is {a:string, b:number}.
const greet = someMap.a; // TS knows greet is string.
const someMapList: {a:string, b:number}[] = [{a: "hi", b: 3},{a: "bye", b:5}];
someMapList.map((m)=> {
// TS can understand the shape of m.
})
Ancak Dart'ta sadece Map<K,V> buluyorum. Aynı görevleri nasıl gerçekleştirebilirim?
Cevap #1
Typescript/Javascript'te haritalar Objects gibidir, bu yüzden onların şeklini senin denediğin gibi tanımlamak mümkündür. Ancak Dart'ta durum böyle değildir.
Aynı sonucu elde etmek için kendi Object öğenizi oluşturmalısınız
class CustomObject {
final string a;
final int b;
CustomObject(this.a, this.b);
}
