第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用字符串索引訪問 TypeScript 中的對象值

如何使用字符串索引訪問 TypeScript 中的對象值

慕桂英546537 2022-07-21 21:30:29
我有一個對象,我想使用字符串索引訪問對象值,但是當(dāng)我嘗試在 TypeScript 中執(zhí)行此操作時,我遇到了錯誤。// Declared Globallyconst Orientation = {    value: () => 0,    'next_value': () => someFunction.anotherFunction.sqrt(),};// _textValue type declared _textValue : string;// Declared inside constructorthis._textValue = 'next_value';// value used inside a function_getValue(){    const newValue = Orientation[this._textValue](); }在我使用的地方Orientation[this._textValue]();,我得到的錯誤是:元素隱式具有“any”類型,因為“any”類型的表達(dá)式不能用于索引類型“{ value: () => number; 'next_value': () => 數(shù)字;}'.ts(7053)關(guān)于如何解決這個問題的任何想法?
查看完整描述

1 回答

?
慕森卡

TA貢獻(xiàn)1806條經(jīng)驗 獲得超8個贊

main.ts


export {}


interface IDictionary {

    [index: string]: string;

}

var params = {} as IDictionary;


//array with string index 

params = {a: "Bhavesh",b: "Bond", c: "Urmil"};


//get array data using string index

var getData = params['b']; // output: Bond

var getData = params['B']; // output: undefined


console.log(getData);

我認(rèn)為您的問題將在上面的示例代碼中得到解決。謝謝你..!



查看完整回答
反對 回復(fù) 2022-07-21
  • 1 回答
  • 0 關(guān)注
  • 175 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號