Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate 1 file to ko - Indexed Access Types.md #142

Merged

Conversation

bumkeyy
Copy link
Contributor

@bumkeyy bumkeyy commented Mar 6, 2022

45a33fe

리뷰 부탁드려요~

추가로 index를 "색인화" 말고 그냥 인덱스라고 번역했는데 어떤가요??
의견 부탁드립니다.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2022

Thanks for the PR!

This section of the codebase is owned by @bumkeyy, @yeonjuan, @guyeol, and @dvlprsh - if they write a comment saying "LGTM" then it will be merged.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2022

Translation of Indexed Access Types.md

title: Indexed Access Types
layout: docs
permalink: /ko/docs/handbook/2/indexed-access-types.html

oneline: "Type['a'] Use syntax to access internal elements of a type"

To find a specific property of the type Indexed access types You can use .

type Person = { age: number; name: string; alive: boolean };
type Age = Person["age"];
//   ^?

The indexed type is a type in itself, so union, keyof Or it can be used for the whole type.

type Person = { age: number; name: string; alive: boolean };
// ---cut---
type I1 = Person["age" | "name"];
//   ^?

type I2 = Person[keyof Person];
//   ^?

type AliveOrName = "alive" | "name";
type I3 = Person[AliveOrName];
//   ^?

If you try to index a property that does not exist, you get an error.

// @errors: 2339
type Person = { age: number; name: string; alive: boolean };
// ---cut---
type I1 = Person["alve"];

Another example is that any type numberto get the type of array element.
typeofWhen combined with , you can conveniently capture element types for array literals.

const MyArray = [
  { name: "Alice", age: 15 },
  { name: "Bob", age: 23 },
  { name: "Eve", age: 38 },
];

type Person = typeof MyArray[number];
//   ^?
type Age = typeof MyArray[number]["age"];
//   ^?
// Or
type Age2 = Person["age"];
//   ^?

Used for variable references when indexing constcannot be used, only type is available.

// @errors: 2538 2749
type Person = { age: number; name: string; alive: boolean };
// ---cut---
const key = "age";
type Age = Person[key];

However, you can use type aliases with similar styles of refactors.

type Person = { age: number; name: string; alive: boolean };
// ---cut---
type key = "age";
type Age = Person[key];

Generated by 🚫 dangerJS against 45a33fe

@yeonjuan
Copy link
Contributor

LGTM

@github-actions github-actions bot merged commit 73f1439 into microsoft:main Nov 16, 2022
@github-actions
Copy link
Contributor

Merging because @yeonjuan is a code-owner of all the changes - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants