How to declare an array with elements of different types in TypeScript?
Hello everyone! I just started learning TypeScript and ran into a problem. In regular JavaScript, I can easily create an array containing elements of different types, for example:\n\n```javascript\nconst data = [1, "hello", true, { name: "John" }];\n```\n\nBut when I try to do the same in TypeScript, the compiler complains or infers a type that doesn't suit me. I tried to explicitly specify the array type:\n\n```typescript\nconst data: Array = [1, "hello", true];\n```\n\nBut this doesn't work — TypeScript says that Array requires specifying the element type. Then I tried `Array`:\n\n```typescript\nconst data: Array = [1, "hello", true];\n```\n\nThis seems to work, but I've heard that using `any` is bad practice because it loses type safety.\n\nI need to declare an array that co
No answers yet.
Log in to leave an answer