TypeScript 型定義の練習
Click to focus
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
interface User {↵
  id: string;↵
  name: string;↵
  email: string;↵
  age?: number;↵
}↵
↵
type UserRole = "admin" | "user" | "guest";↵
↵
const createUser = (name: string, role: UserRole): User => {↵
  return {↵
    id: crypto.randomUUID(),↵
    name,↵
    email: `${name}@example.com`,↵
  };↵
};
1:10
Ln 1, Col 1
UTF-8•TypeScript