It's my first post on Stack Overflow, so i'll try to explain the best I can ! I have this JSON file that is nammed phrases.JSON :
{
"start": {
"affirmative": [
some strings
],
"interrogative": [
some strings
]
},
"mid": [
some strings
]
}
So I import it in another file as phrases, with import phrases from '../utils/phrases.json'
, and declare in modules.d.ts with that.
declare module '*.json' {
const data: any
export default data
}
I made an interface in the file where I imported phrases.json, just like that :
interface Phrases {
[key: string]: TypePhrases | string[]
start: TypePhrases
mid: string[]
}
interface TypePhrases {
[key: string]: string[]
affirmative: string[]
interrogative: string[]
}
In my class, I created a function :
private getPhrases(position: string | number) {
return phrases[position]
}
So if I call this function in my class, i want to get the start object if I give the string 'start', or the string array if I give 'mid', just like that :
const MID_STRING: string = 'mid'
console.log(this.getPhrases(MID_STRING)[0])
But in my return function, I get this error :
Element implicitly has an 'any' type because expression of type 'string | number' can't be used to index type '{ "start": { "affirmative": string[]; "interrogative": string[]; }; "mid": string[]; }'. No index signature with a parameter of type 'string' was found on type '{ "start": { "affirmative": string[]; "interrogative": string[]; }; "mid": string[]; }'.
Could you help me please ? I tried so much things, I don't know how to resolve it... Thanks !
phrases
defined ? – Titian Cernicova-Dragomir