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 - Typeof Type Operator.md #140

Merged

Conversation

bumkeyy
Copy link
Contributor

@bumkeyy bumkeyy commented Mar 5, 2022

e1eedfa

리뷰 부탁드려요~

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 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 5, 2022

Translation of Typeof Type Operator.md

title: Typeof Type Operator
layout: docs
permalink: /ko/docs/handbook/2/typeof-types.html

oneline: "Using the typeof operator in a type context."

typeof Type operator

In JavaScript, Expression contextually available typeof There is an operator.

// "string"을 출력합니다
console.log(typeof "Hello world");

TypeScript type You can infer the type of variable or property in the context. typeof Add an operator.

let s = "hello";
let n: typeof s;
//  ^?

It's not very useful for basic types, but it's with other type operators. typeofYou can use to conveniently represent many patterns.
For example, a predefined type: ReturnType<T> Let's take a look at it.
The above type Function type provides the type returned while receiving .

type Predicate = (x: unknown) => boolean;
type K = ReturnType<Predicate>;
//   ^?

In function name ReturnTypeWith , you can check for instructional errors.

// @errors: 2749
function f() {
  return { x: 10, y: 3 };
}
type P = ReturnType<f>;

value and type Keep in mind that is not the same.
value f of type To infer typeofUse .

function f() {
  return { x: 10, y: 3 };
}
type P = ReturnType<typeof f>;
//   ^?

restriction

TypeScript typeofIntentionally limits the kinds of expressions that can be used.

In particular, only identifiers (e.g. variable name) or properties typeofyou can use .
It can help you avoid the mistakes of writing code that you think is running, but that's not the case.

// @errors: 1005
declare const msgbox: () => boolean;
// type msgbox = any;
// ---cut---
// Meant to use = ReturnType<typeof msgbox>
let shouldContinue: typeof msgbox("Are you sure you want to continue?");

Generated by 🚫 dangerJS against e1eedfa

@bumkeyy
Copy link
Contributor Author

bumkeyy commented Nov 22, 2022

LGTM

@github-actions github-actions bot merged commit 5b74a69 into microsoft:main Nov 22, 2022
@github-actions
Copy link
Contributor

Merging because @bumkeyy 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.

1 participant