JS Built-ins
TypeScriptbeginner

Interface β€” createUser

πŸ“– Usage Example
interface User { name: string; age: number }
const u: User = createUser('Alice', 30)
// β†’ { name: 'Alice', age: 30 }

An interface defines the required shape β€” any object with matching properties satisfies it.

Interfaces: Basic Shape

Interfaces define the shape of an object. TypeScript uses structural typing β€” any object with matching properties satisfies an interface.

Challenge: Implement createUser(name, age) returning an object with name: string and age: number.

createUser('Alice', 30)  // β†’ { name: 'Alice', age: 30 }
πŸ’‘ Hints (1)
  • β€’ Object shorthand: { name, age } is shorthand for { name: name, age: age }.