0
私は、インデックス付きストアインスタンスをリスト静的プロパティを持っているしたいのですが、それ悲しいかな、次のエラーで、コンパイルされません。インデックス付きコレクションをtypescriptの静的プロパティとして書き込む方法はありますか?
Type '({ '0750078': Store; } | { '0840021': Store; } | { '0840302': Store; })[]' is not assignable to type '{ string: Store; }[]'.
Type '{ '0750078': Store; } | { '0840021': Store; } | { '0840302': Store; }' is not assignable to type '{ string: Store; }'.
Type '{ '0750078': Store; }' is not assignable to type '{ string: Store; }'.
Object literal may only specify known properties, and ''0750078'' does not exist in type '{ string: Store; }'.
任意のアイデア?
export class Geolocation {
lat:number;
long: number;
heading: number;
}
export class Store {
nim: string;
name: string;
address: string;
geolocation: Geolocation;
constructor(
nim: string,
name: string,
address: string,
geolocation: Geolocation) {
this.nim = nim;
this.name = name;
this.address = address;
this.geolocation.lat = geolocation.lat;
this.geolocation.long = geolocation.long;
this.geolocation.heading = geolocation.heading;
}
}
export class Stores {
store: Store;
static stores: {string: Store}[] = [
{'0750078': new Store('0750078', 'Kiosque de Paris', 'Place Colette 75001 Paris', new Geolocation(48.8632, 2.3363, 90))},
{'0840021': new Store('0840021', 'Presse tabac', 'Place de l’église 84140 Montfavet', new Geolocation(43.9361, 4.8717, 180))},
];
}
私はまだ問題に直面しています。Stores.stores ['0840021']は未定義を返しますか?どのように@合同? –
あなたは配列として持っています。 [1]は2番目の要素にアクセスします。それをインデクサにするつもりですか?その場合はオブジェクトでなければなりません – unional
私の最初の質問は、店舗をそのNIM( '0840021'のようなキー)で照合することでした。 –