๐*.d.ts
Typescriptํ์ผ์์ JSํ์ผ์ ํธ์ถํ ๊ฒฝ์ฐ ํ์ ์ ์ฝ์ง ๋ชปํ๋ฏ๋ก, Typscript์๊ฒ JSํ์ผ์ ํ์ ์ ๋ํด ์ค๋ช ์ ํด์ค์ผ ํ๋ ์ญํ ์ด๋ค. ์ด๋ ๊ฒ ์ค๋ช ๋์ด ์๋ ํ์ผ์ Declaration File ์ด๋ผ๊ณ ํ๋ค
์์
musicPlay.ts ๋ผ๋ ํ์ผ์์ playMusic๋ผ๋ ํจ์๊ฐ ์๊ณ , date.js์ isPlayOk๋ผ๋ ํจ์๋ฅผ ํตํด ์ฌ์ํ๋ ํจ์๊ฐ ์๋ค
musicPlay.ts
import { isPlayOK } from "@/utils/date";
function playMusic(url: string, date: string): boolean {
// ์ธ๋ถ JS ํธ์ถ
isPlayOK(date);
return true;
}
export {};
date.js
function isPlayOK(date) {
// ๋ณต์กํ๊ณ์ฐ ํ true / false ๋ฆฌํด
return true;
}
export { isPlayOK };
์๋์ ๊ฐ์ด jsํ์ผ์ ํธ์ถํ๋ ๊ณณ์์ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค

๊ฒฐ๊ตญ์ jsํ์ผ์์ ์ด์๊ฐ ๋ฐ์ํ๋ฏ๋ก, js์ ๋ํ Declaration File์ด ํ์ํ๋ค
global.d.ts
declare module "@/utils/date" {
declare function isPlayOK(data: string): boolean;
}
์์ ๊ฐ์ด date.js์ isPlayOk์ ๋ํด ํ์ ์ ๋ํด ๋ฏธ๋ฆฌ ์ ์ ํด๋๋ค.
๋ค๋ง ์ ํ์ผ ์์ฑ์์๋ jsํ์ผ์ ๋ํ **“์ ํํ ๊ธฐ๋ฅ์ด๋, ๋ฆฌํดํ์ “**์ ๋ํด ์ธ์ง๋ฅผ ํ๊ณ ์์ด์ผ ํ๋ค

Record
Key,Valueํํ ์ด๋ฉฐ, Key,value์ ํ์ ์ ์ง์ ํ ์ ์๋ค
interface PageValue {
title: string;
}
type PageKey = "home" | "about" | "contact";
const nav: Record<PageKey, PageValue> = {
contact: { title: "t1" },
about: { title: "t2" },
home: { title: "t3" },
};
Omit
Type์์ ์ํ๋ ํค ๊ฐ์ ์ ๊ฑฐํ๋ ๊ธฐ๋ฅ
// Omit
// Type์์ ์ํ๋ ํค ๊ฐ์ ์ ๊ฑฐํ๋ ๊ธฐ๋ฅ
interface Person {
name: string;
age: number;
country: string;
gender: "m" | "w";
likefood: string;
}
type KoreaPerson = Omit<Person, "likefood">;
// name,age,country,gender'typescript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ํ์ ์คํฌ๋ฆฝํธ ์ ๋ค๋ฆญ ์ ํ (0) | 2025.02.26 |
|---|---|
| ๐ ํ์ ์คํฌ๋ฆฝํธ ์ ๋ค๋ฆญ (0) | 2025.02.07 |
| ๐ ํ์ ์คํฌ๋ฆฝํธ ํจ์ (0) | 2025.01.18 |
| ๐ฆถ ํ์ ์คํฌ๋ฆฝํธ ์ธํฐํ์ด์ค (0) | 2025.01.12 |
| ๐ง ํ์ ์คํฌ๋ฆฝํธ ๊ธฐ๋ณธ ํ์ (0) | 2025.01.03 |
๋๊ธ