Skip to content

7 - Readonly #2

@DEV4N4

Description

@DEV4N4
// your answers
type MyReadonly<T> = {
  readonly [K in keyof T] : T[K]
}

keyof는 주어진 객체 타입에서 모든 키를 Union 타입으로 변환합니다.

예를 들어, userInfo라는 인터페이스가 있을 때:

interface userInfo {
  name: string;
  age: number;
}

type keyofValue = keyof userInfo;
// keyofValue = "name" | "age"

위 코드에서 keyof userInfo는 userInfo 인터페이스의 모든 키를 union 타입으로 반환합니다. 즉, keyofValue는 "name" | "age"가 됩니다. 이는 userInfo 객체에서 name과 age라는 키를 선택할 수 있다는 의미입니다.

Metadata

Metadata

Assignees

No one assigned

    Labels

    answerShare answers/solutions to a question

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions