Uh oh!
There was an error while loading. Please reload this page.
Translate 1 file to ko - TypeScript 4.1.md - #94
Conversation
Thanks for the PR! This section of the codebase is owned by Kibeom Kwon (@bumkeyy), YeonJuan (@yeonjuan), and Dan Jeong (@guyeol) - if they write a comment saying "LGTM" then it will be merged. |
Translation of TypeScript 4.1.mdtitle: TypeScript 4.1 oneline: TypeScript 4.1 Release NotesTemplate Literal TypesIn TypeScript, string literal types enable you to model functions and APIs that anticipate a set of specific strings. // @errors: 2345functionsetVerticalAlignment(location: "top"|"middle"|"bottom"){// ...}setVerticalAlignment("middel");This is pretty good in that the string literal type can spell check for string values by default. typeOptions={[Kin"noImplicitAny"|"strictNullChecks"|"strictFunctionTypes"]?: boolean;};// same as// type Options = {// noImplicitAny?: boolean,// strictNullChecks?: boolean,// strictFunctionTypes?: boolean// };However, there are other cases where you can use those string literal types like architectural blocks: when you create other string literal types, For the above reasons, Typescript 4.1 added a template literal string type. typeWorld="world";typeGreeting= `hello ${World}`;// ^?What happens if you use it instead of a union type? This generates a set of all string literals that each union members can represent. typeColor="red"|"blue";typeQuantity="one"|"two";typeSeussFish= `${Quantity|Color} fish`;// ^?These can be used in more places than cute examples in release notes. For example, various UI component libraries often provide a way to align vertically and horizontally, often // @errors: 2345typeVerticalAlignment="top"|"middle"|"bottom";typeHorizontalAlignment="left"|"center"|"right";// Takes// | "top-left" | "top-center" | "top-right"// | "middle-left" | "middle-center" | "middle-right"// | "bottom-left" | "bottom-center" | "bottom-right"declarefunctionsetAlignment(value: `${VerticalAlignment}-${HorizontalAlignment}`): void;setAlignment("top-left");// works!setAlignment("top-middel");// error!setAlignment("top-pot");// error! but good doughnuts if you're ever in SeattleAn example of sorting the UI API A lot Despite this, this is still only a simple example in that we write it passively. The real value of this comes from dynamically creating new string literals. letperson=makeWatchedObject({firstName: "Homer",age: 42,// give-or-takelocation: "Springfield",});person.on("firstNameChanged",()=>{console.log(`firstName was changed!`);});Where the on method is How do I type the on method? typePropEventSource<T>={on(eventName: `${string&keyofT}Changed`,callback: ()=>void): void;};/// 감시 대상 객체를 on 메소드와 함께 만들어서/// 프로퍼티의 변화를 감시할 수 있게됩니다.declarefunctionmakeWatchedObject<T>(obj: T): T&PropEventSource<T>;As such, if an incorrect value comes in, you can create an error! // @errors: 2345typePropEventSource<T>={on(eventName: `${string&keyofT}Changed`,callback: ()=>void): void;};declarefunctionmakeWatchedObject<T>(obj: T): T&PropEventSource<T>;letperson=makeWatchedObject({firstName: "Homer",age: 42,// 대략location: "Springfield",});// ---생략---// error!person.on("firstName",()=>{});// error!person.on("frstNameChanged",()=>{});You can also use template literal types to do something special. : Inferred at the position of substitution (infer) In the example above, you can identify the relevant typePropEventSource<T>={on<Kextendsstring&keyofT>(eventName: `${K}Changed`,callback: (newValue: T[K])=>void): void;};declarefunctionmakeWatchedObject<T>(obj: T): T&PropEventSource<T>;letperson=makeWatchedObject({firstName: "Homer",age: 42,location: "Springfield",});// 작동합니다! 'newName'의 타입은 'string'입니다.person.on("firstNameChanged",newName=>{// 'newName'의 타입은 'fistName'의 타입과 같습니다. console.log(`new name is ${newName.toUpperCase()}`);});// 작동합니다! 'newAge'의 타입은 'number'입니다.person.on("ageChanged",newAge=>{if(newAge<0){console.log("warning! negative age");}})In generic methods Inference can be combined in different ways to decompose and reconstruct strings. typeEnthusiasticGreeting<Textendsstring>= `${Uppercase<T>}`
typeHELLO=EnthusiasticGreeting<"hello">;// ^?New type aliases The front two replace all characters, and the back two replace only the first character. For more information, see Check the original pull request. and Ongoing pull request to replace with type alias helperCheck it out too. Key Remapping in Mapped TypesFirst of all, the mapping type is used to create new objects based on arbitrary keys, typeOptions={[Kin"noImplicitAny"|"strictNullChecks"|"strictFunctionTypes"]?: boolean;};// same as// type Options = {// noImplicitAny?: boolean,// strictNullChecks?: boolean,// strictFunctionTypes?: boolean// };Alternatively, you can create new object types based on different object types. /// 'Partial<T>'가 'T'와 같지만, 각 프로퍼티는 선택 사항으로 표시되어 있음.typePartial<T>={[KinkeyofT]?: T[K];};Until now, mapped types had to have keys provided to create new object types. However, in most cases, you can create a new key based on input, or filter the key. This is why Typescript 4.1 typeMappedTypeWithNewKeys<T>={[KinkeyofTasNewKeyType]: T[K]// ^^^^^^^^^^^^^// 이것이 새 문법입니다!}This new typeGetters<T>={[KinkeyofTas `get${Capitalize<string&K>}`]: ()=>T[K]};interfacePerson{name: string;age: number;location: string;}typeLazyPerson=Getters<Person>;// ^?and // 'kind' 프로퍼티를 삭제하기typeRemoveKindField<T>={[KinkeyofTasExclude<K,"kind">]: T[K]};interfaceCircle{kind: "circle";radius: number;}typeKindlessCircle=RemoveKindField<Circle>;// ^?For more information, see: Original pull request on GithubCheck it out. Recursive Condition TypesIn JavaScript, functions that can be created and leveled container types at any level are common. For all practical intents and purposes, it is impossible to describe this in type systems in TypeScript. typeElementType<T>=TextendsReadonlyArray<infer U> ? ElementType<U> : T;functiondeepFlatten<Textendsreadonlyunknown[]>(x: T): ElementType<T>[]{throw"not implemented";}// 모두 'number[]' 타입을 반환합니다.deepFlatten([1,2,3]);deepFlatten([[1],[2,3]]);deepFlatten([[1],[[2]],[[[3]]]]);Similarly, in TypeScript 4.1, typeAwaited<T>=TextendsPromiseLike<infer U> ? Awaited<U> : T;/// `promise.then(...)`과 비슷하지만, 타입에 대해서는 더 정확함.declarefunctioncustomThen<T,U>(p: Promise<T>,onFulfilled: (value: Awaited<T>)=>U): Promise<Awaited<U>>;These recursive types are powerful but responsible and should be used with less. First, these recursive types do a lot of work, thus increasing the type verification time. In addition, leaving compute-intensive, these types can reach the internal recursive depth limit for sufficiently complex inputs. SupplementsSee . Checked Indexed Accesses ( |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
YeonJuan (yeonjuan)
left a comment
There was a problem hiding this comment.
조민수 (@minsoo0715) 번역 감사합니다. :) 전반적으로 문단 구분을 원본과 맞춰야 할 것 같습니다.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
YeonJuan (yeonjuan)
commented
Aug 3, 2021
조민수 (@minsoo0715) 고생하셨습니다 :) 아직 전부다 자세히 읽어보진 않았습니다. 눈에 띄는 부분 코멘트 남겼습니다 👍 |
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
Co-authored-by: YeonJuan <yeonjuan93@naver.com>
조민수 (minsoo0715)
commented
Aug 8, 2021
꼼꼼한 리뷰 감사드립니다. 🙏 사소한 결점들이 너무 많네요. |
en
TypeScript 4.1.md 번역완료했습니다.
어색한 부분이 있거나 틀린 부분있으면 코멘트 부탁드립니다🙏
ref #6