Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof import' No index signature with a parameter of type 'string' was found on type
케이 (3)2022년 9월 02일
Tags #error

image

import * as A from 'A'
했을 때 A[index] 이런 식으로 접근을 하면 에러가 발생한다.

대략 이런 에러다.

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof import' No index signature with a parameter of type 'string' was found on type

Index Signature를 추가해서 해결할 수 있다.

import * as A from './file'
const B: { [key in string]: any } = A

let i = 1 
for (const index of Object.keys(keywordSetting)) {
	if (i++ > 3) break
	console.log(index)
	const result = await B[index](keywordSetting[index], keywordScore, keywordInfo, dataSet)
	keywordInfo[index] = result.check
	keywordScore = result.keywordScore
}
console.log(Object.entries(keywordInfo).filter((e: any) => e[1].text))

0개의 댓글