Declare a string name and an array of lucky numbers in TypeScript
Primitive and array type annotations in TypeScript.
Declare the name with a lowercase string type and the lucky numbers as number[] or Array<number>.
Using uppercase String or Number, or omitting the array type.
WHAT THIS TESTS: This question checks your familiarity with TypeScript's most basic type annotations for primitives and arrays. The interviewer wants to see if you know the correct lowercase type names and the standard array syntax. Even at senior levels, a precise answer signals disciplined type safety and shows you do not rely on implicit any. It also reveals whether you understand the difference between a primitive value type and its corresponding wrapper object. Demonstrating this fluency quickly builds confidence that you can handle more complex type constructs later in the interview without drifting toward unsafe any types.
A GOOD ANSWER COVERS: A strong response declares the name variable with the string type, for example const userName: string = "Alice". It then declares the lucky numbers using an array of numbers, written as const luckyNumbers: number[] = [7, 13, 21] or equivalently const luckyNumbers: Array<number> = [7, 13, 21]. You should explicitly state that TypeScript uses lowercase string and number for types, while capitalized String and Number refer to rare built-in wrapper types that are almost never used for annotations. You can also note that const is preferable when the binding will not be reassigned, though let is acceptable if the variable must be replaced later in the program.
COMMON WRONG ANSWERS: The biggest red flag is using uppercase wrapper types like String or Number, which reveals confusion between JavaScript primitives and their object wrappers. Another mistake is writing let luckyNumbers = [7, 13] without a type annotation and without context that TypeScript can infer it; in strict mode this can trigger errors or imply sloppy typing. Some candidates incorrectly write [number], which defines a tuple containing exactly one number rather than an array of any length. Declaring the array as any[] or omitting the type entirely also signals weak type safety habits and a lack of attention to compiler strictness.
LIKELY FOLLOW-UPS: The interviewer might ask when to use const versus let for these declarations. They may also ask you to make the array read-only using ReadonlyArray<number> or readonly number[]. Another follow-up could involve typing an array of mixed strings and numbers, or asking you to explain the difference between number[] and Array<number> in the context of generics and which style your team prefers.
ONE CONCRETE EXAMPLE: Here is a clean declaration block: const userName: string = "Alice"; const luckyNumbers: number[] = [7, 13, 21];. If you need an immutable list, you would write const luckyNumbers: readonly number[] = [7, 13, 21]; to prevent pushes and reassignments.
Read the original → typescriptlang.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.