🖥

error TS7053: Element implicitly has an 'any' type because expression

に公開

const props : any = {}

props["A"] = "a"
props["B"] = { "b": "c"}

console.log(props["A"]) // a

console.log(props["B"]) // { b: 'c' }

// When not specify "any"
// raise error on type script build

// const props  = {}

// props["A"] = "a"
// props["B"] = { "b": "c"}


// $ tsc --strict props.ts
// ../.ghq/github.com/YumaInaura/YumaInaura/type-script/props.ts:8:1 - error TS7053: Element implicitly has an 'any' type because expression of type '"A"' can't be used to index type '{}'.
//   Property 'A' does not exist on type '{}'.

// 8 props["A"] = "a"
//   ~~~~~~~~~~

// ../.ghq/github.com/YumaInaura/YumaInaura/type-script/props.ts:9:1 - error TS7053: Element implicitly has an 'any' type because expression of type '"B"' can't be used to index type '{}'.
//   Property 'B' does not exist on type '{}'.

// 9 props["B"] = { "b": "c"}
//   ~~~~~~~~~~


// Found 2 errors.

// const props = {}

Original by Github issue

https://github.com/YumaInaura/YumaInaura/issues/3017

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2020-03-15

Discussion