내용으로 건너뛰기
GaramX
사용자 도구
로그인
사이트 도구
검색
도구
문서 보기
이전 판
역링크
최근 바뀜
미디어 관리자
사이트맵
로그인
>
최근 바뀜
미디어 관리자
사이트맵
현재 위치:
home
»
typescript
»
cheat_sheet
추적:
•
typescript
typescript:cheat_sheet
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
====== Cheat Sheet ====== === Usage === ''npm install typescript'' ''tsc'' === Primitive types === ^Primitive types^^ |Any type (explicitly untyped) |''any'' | |void type (undefined or null, use for function returns only) |''void'' | |Undefined type |''undefined'' | |Null type |''null''| |never type |''never''| |unknown type |''unknown''| |String (including ES6 multi-line string templates) |''string''| |Number |''number''| |Boolean |''boolean''| |object (may be an Object or non-primitive) |''object''| === Named types (interface, class, enum) === ^Named types (interface, class, enum)^^ |Interface |<code:javascript> interface Child extends Parent, SomeClass { property: Type; optionalProp?: Type; optionalMethod?(arg1: Type): ReturnType; }</code>| |Class |<code:javascript> class Child extends Parent implements Child, OtherChild { property: Type; defaultProperty: Type = 'default value'; private _privateProperty: Type; private readonly _privateReadonlyProperty: Type; static staticProperty: Type; constructor(arg1: Type) { super(arg1); } private _privateMethod(): Type {} methodProperty: (arg1: Type) => ReturnType; overloadedMethod(arg1: Type): ReturnType; overloadedMethod(arg1: OtherType): ReturnType; overloadedMethod(arg1: CommonT): CommonReturnT {} static staticMethod(): ReturnType {} subclassedMethod(arg1: Type): ReturnType { super.subclassedMethod(arg1); } }</code> | |Enum |<code:javascript> enum Options { FIRST, EXPLICIT = 1, BOOLEAN = Options.FIRST | Options.EXPLICIT } enum Colors { Red = "#FF0000", Green = "#00FF00", Blue = "#0000FF" }</code> | === Object type literals === ^Object type literals^^ |Object with implicit Any properties |''{ foo; bar; }''| |Object with optional property |''{ required: Type; optional?: Type; }''| |Hash map |''{ [key: string]: Type; }''| === Union and intersection types === ^Union and intersection types^^ |Union type |''let myUnionVariables: number | string;'' | |Intersection type |''let myIntersectionType: Foo & Bar;'' | === Arrays and tuples === ^Arrays and tuples^^ |Array of strings |<wrap>''string[]'' or ''Array<string>''</wrap> | |Array of functions that return strings |<wrap>''{(): string; }[]'' or ''Array<() => string>''</wrap> | |Tuples |<wrap>''let myTuple: [ string, number, boolean? ]; myTuple = [ 'test', 42 ];''</wrap> | === Functions === ^Functions^^ ^Function |<wrap>''{ (arg1: Type, argN: Type): Type; }'' or ''(arg1: Type, argN: Type) => Type;''</wrap> | ^Constructor |<wrap>''{ new (): ConstructedType; }'' or ''new () => ConstructedType;''</wrap> | ^Function type with optional param |''(arg1: Type, optional?: Type) => ReturnType'' | ^Function type with rest param |''(arg1: Type, ...allOtherArgs: Type[]) => ReturnType'' | ^Function type with static property |''{ (): Type; staticProp: Type; }'' | ^Default argument |''function fn(arg1: Type = 'default'): ReturnType {}'' | ^Arrow function |<wrap>''(arg1: Type): ReturnType => {}'' or ''(arg1: Type): ReturnType => Expression''</wrap> | ^this typing |''function fn(this: Foo)'' | === Generics === ^Generics^^ ^Function using type parameters |''<T>(items: T[], callback: (item: T) => T): T[]'' | ^Interface with multiple types |<wrap>''interface Pair<T1, T2> { first: T1; second: T2; }''</wrap> | ^Constrained type parameter |''<T extends ConstrainedType>(): T'' | ^Default type parameter |''<T = ConstrainedType>(): T'' | ^Constrained and default type parameter |''<T extends ConstrainedType = ConstrainedType>(): T'' | === Partial and mapped types === ^Partial and mapped types^^ ^Partial type |<wrap>''Partial<{ x: number; y: number; z: number; }>'' is equivalent to ''{ x?: number; y?: number; z?: number; }''</wrap> | ^Readonly type |<wrap>''Readonly<{ x: number; y: number; z: number; }>'' is equivalent to ''{ readonly x: number; readonly y: number; readonly z: number; }''</wrap> | ^Pick type |<wrap>''Pick<{ x: number; y: number; z: number; }, 'x' | 'y'>'' is equivalent to ''{ x: number; y: number; }''</wrap> | ^Record type |<wrap>''Record<'x' | 'y' | 'z', number>'' is equivalent to ''{ x: number; y: number; z: number; }''</wrap> | === Conditional types === ^Conditional types^^ ^Conditional types |''declare function createLabel<T extends number | string>(idOrName: T): T extends number ? Id : Name;'' | ^Exclude |<wrap>''type Excluded = Exclude<string | number, string>;'' is equivelant to ''number''</wrap> | ^Extract |<wrap>''type Extracted = Extract<string | number, string>;'' is equivelant to ''string''</wrap> | ^NonNullable |<wrap>''type NonNull = NonNullable<string | number | void>;'' is equivalent to ''string | number''</wrap> | ^ReturnType |<wrap>''type ReturnValue = ReturnType<() => string>;'' is equivalent to ''string''</wrap> | ^InstanceType |<wrap>''class Renderer() {} type Instance = InstanceType<typeof Renderer>;'' is equivalent to ''Renderer''</wrap> | === Other === ^Other^^ ^Type of a variable |''typeof varName'' |
typescript/cheat_sheet.txt
· 마지막으로 수정됨: 2025/04/15 10:05 저자
127.0.0.1
문서 도구
문서 보기
이전 판
역링크
맨 위로