I have a question about mixed types in object values
I have an empty object with interface that I fill out later with the code. I add strings and numbers to it.
interface CardDataObject {
[key: string]: any
}
const data: CardDataObject = {}
data.number = number
data.string = string
That's how I add items later
With 'any' everything works fine, but my teacher says that I have to define it better and without 'any' type
Is there any way to create a universal interface for an object not knowing the type of values in advance?
Your teacher is right,
anyis to avoid at all cost because it basically disables TypeScript so it's like you write plain JavaScript.You add strings and numbers to it? Then type it like this:
Shortest variant: