Typescript
π οΈ μμ΄μ νΈ μ€ν¬
npx -y skills add DaleStudy/skills --skill typescriptAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
TypeScript νμ μ μ λ° λ² μ€νΈ νλν°μ€ μ€ν¬. λ€μ μν©μμ μ¬μ©: (1) TypeScript νμΌ(.ts, .tsx) μμ± λλ μμ μ, (2) νμ μ μ(interface, type) μμ μ, (3) tsconfig.json μ€μ λλ μ»΄νμΌλ¬ μ΅μ μ‘°μ μ, (4) νμ μλ¬ ν΄κ²° λλ νμ μμ μ± κ°μ μ, (5) μ λ€λ¦, μ νΈλ¦¬ν° νμ , νμ μ‘°μ μμ μ, (6) 'typescript', 'ts', 'type', 'interface', 'generic' ν€μλκ° ν¬ν¨λ μμ μ
The file declares its own license as MIT. That is the authorβs claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
4.8 KB, as published. Nobody here has run it
TypeScript
TypeScript νΈλλΆ κΈ°λ° νμ μ μ λ° λ² μ€νΈ νλν°μ€. κΈ°λ³Έ λ¬Έλ²Β·νμ μ‘°μΒ·μ νΈλ¦¬ν° νμ μμΈλ references/ λ° Handbook μ°Έκ³ .
κΈ°λ³Έ μμΉ
1. νμ μΆλ‘ νμ©
λΆνμν μ΄λ Έν μ΄μ μλ΅. λ³κ²½ μ μ΄μ€ μμ λΆλ΄ κ°μ, μΆλ‘ μ΄ λ μ νν κ²½μ° λ§μ.
// β
const name: string = "John";
const user: { name: string; age: number } = { name: "John", age: 30 };
// β
const name = "John";
const user = { name: "John", age: 30 };
2. λͺ μμ λ°ν νμ
ν¨μ κ³μ½ λͺ νν, λ°ν νμ μ€λ³κ²½ λ°©μ§. κ³΅κ° API·볡μ‘ν λ‘μ§μμ νμ.
function calculateTotal(items: Item[]): number {
return items.reduce((sum, item) => sum + item.price, 0);
}
async function fetchUser(id: string): Promise<User> {
const res = await fetch(`/api/users/${id}`);
return res.json();
}
3. any μ¬μ© κΈμ§
νμ
μμ μ±Β·μλμμ± λ¬΄ν¨ν. unknown + νμ
κ°λ λλ ꡬ체 νμ
μ¬μ©.
// β
function process(data: any) {
return data.value;
}
// β
function process(data: unknown): number {
if (typeof data === "object" && data !== null && "value" in data)
return (data as { value: number }).value;
throw new Error("Invalid data");
}
ν¨μ Β· μ λ€λ¦
- ν¨μ: μΈμΒ·λ°ν νμ λͺ μ. μ€λ²λ‘λ μ ꡬν μκ·Έλμ²λ μ λμ¨μΌλ‘.
- μ λ€λ¦:
T,K extends keyof Tλ± μ μ½ λͺ μ.getProperty<T, K extends keyof T>(obj: T, key: K): T[K]ν¨ν΄ νμ©.
νμ κ°λ
typeof,instanceof,inμΌλ‘ λΆκΈ° ν νμ μ’νκΈ°- 볡μ‘ν κ²μ¬λ μ¬μ©μ μ μ κ°λ
(value): value is Tμ¬μ©
ν νλ¦Ώ:
assets/types.guards.ts
tsconfig
- νλ‘μ νΈ μ±κ²©μ λ§λ tsconfigλ₯Ό μ¬μ©
- νμ μμ μ±μ ν΄μΉμ§ μλ μ μμλ§ μ΅μ μ μ‘°μ
- μ±/μλ²/λΌμ΄λΈλ¬λ¦¬λ μ€μ νμΌμ λΆλ¦¬
- νμ μλ¬ ννΌ λͺ©μ μ μ΅μ μν κΈμ§
ν νλ¦Ώ:
assets/tsconfig.nextjs.tsassets/tsconfig.node.tsassets/tsconfig.react.ts
μ΄λ²€νΈ νμ
- DOM / React μ΄λ²€νΈλ λ΄μ₯ νμ μ¬μ©
- 컀μ€ν μ΄λ²€νΈλ§ λ³λ νμ μ μ
- μ΄λ²€νΈ μ¬μ μ κΈμ§
ν νλ¦Ώ:
assets/types.events.ts
μ νΈλ¦¬ν° νμ
- TypeScript λ΄μ₯ μ νΈλ¦¬ν° νμ μ κ·Έλλ‘ μ¬μ©
- 컀μ€ν μ νΈλ¦¬ν° νμ λ§ μ μ
ν νλ¦Ώ:
assets/types.utils.ts
μ€μ ν¨ν΄
- interface μ°μ : κ°μ²΄ κ³μ½Β·νμ₯μ
interface, μ λμ¨/μΈν°μΉμ μtype. API μ€λͺ μ λͺ μ¬νμΌλ‘ μμ± (/** λΉνμ±ν μν */). as const: 리ν°λ΄Β·κ°μ²΄ λΆλ³ 보쑴.typeof obj[keyof typeof obj]λ‘ μ΄λμ²λΌ νμ©.- λΈλλ νμ
:
type UserId = string & { readonly brand: unique symbol }λ‘ λμΌ μμ νμ ꡬλΆ. - νμ
λ¨μΈ μ΅μν:
asλμ νμ κ°λ. - μ λ€λ¦ μ μ½:
T extends objectλ± λͺ μ.
νμ μλ¬ ν΄κ²°
| μλ¬ | λμ |
|---|---|
Type 'X' is not assignable to type 'Y' | νμ κ°λλ‘ λΆκΈ° ν ν λΉ |
Property 'X' does not exist on type 'Y' | νμ
νμ₯ λλ optional |
Object is possibly 'null' or 'undefined' | if (x == null) / ?. / ?? |
Argument of type 'X' is not assignable to parameter of type 'Y' | μ λ€λ¦ T[] λλ μ€λ²λ‘λ |
Type 'X' cannot be used as an index type | keyof typeof obj μ¬μ© |
λλ²κΉ
: νΈλ²λ‘ μΆλ‘ νμΈ, κ°λΒ·μ λ€λ¦Β·μ νΈλ¦¬ν° νμ
μΌλ‘ ν΄κ²° ν asλ μ΅ν μλ¨.
μ°Έκ³
μ΄ λ¬Έμλ€μ κ·μΉμ΄ μλλΌ μ°Έκ³ μ©, νλ¨ κΈ°μ€μ κ° skill λ¬Έμλ₯Ό μ°μ
- TypeScript Handbook - TypeScript 곡μ κ°λ Β·νμ μμ€ν λ νΌλ°μ€
- Playground - νμ λμ μ€ν λ° μμ κ²μ¦μ©