반응형
m.logPrint() is working!
<eq> and <eqq> tags are rendered to MathJax format, being enclosed by \ ( \ ) and \ [ \ ].
docuK1 scripts started!
If this log is not closed automatically, there must be an error somewhere in your document or scripts.
Table of Contents is filled out.
Auto numberings of sections (div.sec>h2, div.subsec>h3, div.subsubsec>h4), <eqq> tags, and <figure> tags are done.
<cite> and <refer> tags are rendered to show bubble reference.
<codeprint> tags are printed to corresponding <pre> tags, only when the tags exist in the document.
Current styles (dark/bright mode, font-family, font-size, line-height) are shown.
disqus.js with id="disqus-js" is loaded.
kakao.js with id="kakao-js-sdk" is loaded.
New ShortKeys (T: Table of Contents, F: Forward Section, D: Previous Section, L: To 전체목록/[Lists]) are set.
m.delayPad=0;
m.wait=1024;
wait 1146ms.
<eq> and <eqq> tags are rendered to MathJax format, being enclosed by \ ( \ ) and \ [ \ ].
docuK1 scripts started!
If this log is not closed automatically, there must be an error somewhere in your document or scripts.
Table of Contents is filled out.
Auto numberings of sections (div.sec>h2, div.subsec>h3, div.subsubsec>h4), <eqq> tags, and <figure> tags are done.
<cite> and <refer> tags are rendered to show bubble reference.
<codeprint> tags are printed to corresponding <pre> tags, only when the tags exist in the document.
Current styles (dark/bright mode, font-family, font-size, line-height) are shown.
disqus.js with id="disqus-js" is loaded.
kakao.js with id="kakao-js-sdk" is loaded.
New ShortKeys (T: Table of Contents, F: Forward Section, D: Previous Section, L: To 전체목록/[Lists]) are set.
m.delayPad=0;
m.wait=1024;
wait 1146ms.







이 글이 도움이 되셨다면, 광고 클릭 한번씩만 부탁드립니다 =ㅂ=ㅋ. (If this article was helpful, please click the ad once. Thank you. ;)
Mode: Bright; Font: Noto Sans KR; font-size: 18.0px (10.0); line-height: 1.6;
width: 1280, height: 720, version: 3.1.1
Canonical URI: https://kipid.tistory.com/entry/12월-09일-2기-위클리-페이퍼-TypeScript의-동작-원리에-대해-설명해-주세요-d-ts-타입-정의파일이-무엇이며-어떻게-만들-수-있는지-설명하세요
dg:plink (Document Global Permanent Link): https://kipid.tistory.com/388
document.referrer: Empty
width: 1280, height: 720, version: 3.1.1
Canonical URI: https://kipid.tistory.com/entry/12월-09일-2기-위클리-페이퍼-TypeScript의-동작-원리에-대해-설명해-주세요-d-ts-타입-정의파일이-무엇이며-어떻게-만들-수-있는지-설명하세요
dg:plink (Document Global Permanent Link): https://kipid.tistory.com/388
document.referrer: Empty







12월 09일 2기 위클리 페이퍼 - TypeScript의 동작 원리에 대해 설명해 주세요. d.ts 타입 정의파일이 무엇이며, 어떻게 만들 수 있는지 설명하세요.
Table of Contents
T1.TypeScript의 동작 원리에 대해 설명해 주세요.
▼ Show/Hide
TypeScript는 JavaScript의 슈퍼셋으로, JavaScript에 정적 타입을 추가한 언어입니다. 동작 원리를 이해하려면 다음 핵심 개념들을 알아야 합니다:
1. 타입 시스템: TypeScript는 변수, 함수 매개변수, 반환 값 등에서 타입을 명시적으로 지정할 수 있게 합니다. 이로 인해 코드를 작성하는 도중에 타입 오류를 발견할 수 있으며, 더 나은 코드 품질과 유지 보수성을 제공합니다.
let myString: string = 'Hello, TypeScript!';
2. 컴파일러: TypeScript 코드는 직접 실행되지 않고, TypeScript 컴파일러 (tsc)에 의해 JavaScript로 변환됩니다. 이 컴파일 과정에서 타입 검사 및 기타 다양한 코드 검사가 수행됩니다.
이 과정에서 코드를 구성하는 키워드, 변수, 함수 등을 인식하고 추상 문법 트리(Abstract Syntax Tree, AST)라는 자료 구조로 변환합니다. AST는 코드의 구조를 트리 형태로 나타내어 컴파일러가 코드를 효율적으로 처리할 수 있도록 합니다.
tsc myFile.ts
3. ES6+ 기능: TypeScript는 최신 ECMAScript 표준을 지원하며, 이를 통해 최신 JavaScript 기능을 사용할 수 있습니다. TypeScript는 이러한 기능들을 구 버전 JavaScript로 변환하여 하위 호환성도 유지합니다.
4. 자바스크립트 상호 운용성: TypeScript는 JavaScript 코드와 호환되므로, 기존 JavaScript 프로젝트에 TypeScript를 점진적으로 도입할 수 있습니다. JavaScript 파일에 TypeScript 기능을 추가하거나, JavaScript 파일을 TypeScript 파일로 변환하는 것이 가능합니다.
5. 타입 추론: TypeScript는 코드의 문맥에 따라 변수의 타입을 자동으로 추론할 수 있습니다. 이는 타입을 명시적으로 지정하지 않아도 타입 안정성을 유지할 수 있게 합니다.
let myNumber = 5; // TypeScript가 자동으로 myNumber를 숫자로 추론
6. 데코레이터: TypeScript는 클래스와 메서드에 데코레이터를 사용하여 메타프로그래밍을 지원합니다. 데코레이터는 클래스나 메서드의 동작을 수정하거나 추가적인 기능을 부여할 수 있는 강력한 도구입니다.
TypeScript는 이러한 특징들을 통해 개발자가 더 안전하고 예측 가능한 코드를 작성할 수 있게 도와줍니다. 타입 시스템과 컴파일러를 통해 코드의 품질을 높이고, 최신 JavaScript 기능을 활용하여 더 나은 개발 경험을 제공합니다.
▲ Hide
T2.d.ts 타입 정의파일이 무엇이며, 어떻게 만들 수 있는지 설명하세요.
▼ Show/Hide
TypeScript의
.d.ts
파일은 타입 정의 파일로, JavaScript 라이브러리나 모듈을 TypeScript에서 사용할 수 있도록 타입 정보를 제공합니다. 이 파일을 통해 TypeScript는 JavaScript 코드의 타입을 알고, 타입 검사 및 코드 자동 완성을 더 정확하게 수행할 수 있습니다.T2.1..d.ts
파일 생성 방법
1. 기본 구조:
.d.ts
파일은 TypeScript의 인터페이스와 타입 선언을 사용하여 모듈의 구조를 설명합니다.// example.d.ts declare module 'example' { export function sayHello(name: string): string; export const version: string; }
2. 전역 변수: 만약 라이브러리가 전역 변수로 동작한다면, 이를 선언할 수 있습니다.
// global-example.d.ts declare var MyGlobalVar: string;
3. 인터페이스와 타입 선언: 모듈 내에서 사용되는 데이터 구조를 설명하기 위해 인터페이스와 타입을 정의할 수 있습니다.
// shapes.d.ts interface Circle { radius: number; color?: string; } interface Square { sideLength: number; color?: string; }
4. 라이브러리 참조: 종속성을 포함하여 다른 타입 정의 파일을 참조할 수 있습니다.
// main.d.ts /// <reference path="./shapes.d.ts" /> declare module 'main' { export function drawShape(shape: Circle | Square): void; }
T2.2.생성 예시
다음은 간단한 예제를 통해 설명합니다:
1. JavaScript 모듈 (example.js)
module.exports.sayHello = function(name) { return `Hello, ${name}!`; }; module.exports.version = '1.0.0';
2. 타입 정의 파일 (example.d.ts)
declare module 'example' { export function sayHello(name: string): string; export const version: string; }
3. TypeScript 사용 예시 (app.ts)
import { sayHello, version } from 'example'; console.log(sayHello('World')); console.log(`Version: ${version}`);
이렇게 타입 정의 파일을 작성하면 TypeScript가 JavaScript 모듈의 타입 정보를 알고, 타입 검사 및 코드 자동 완성을 정확하게 수행할 수 있습니다.
▲ Hide







이 글이 도움이 되셨다면, 광고 클릭 한번씩만 부탁드립니다 =ㅂ=ㅋ. (If this article was helpful, please click the ad once. Thank you. ;)
반응형