Language-tools: [TypeScript] ꡬ성 μš”μ†Œλ₯Ό κ°’μœΌλ‘œ ν¬ν•¨ν•˜λŠ” λ³€μˆ˜ μž…λ ₯

에 λ§Œλ“  2020λ…„ 08μ›” 26일  Β·  6μ½”λ©˜νŠΈ  Β·  좜처: sveltejs/language-tools

TypeScriptλ₯Ό μ‚¬μš©ν•  λ•Œ μ»΄ν¬λ„ŒνŠΈλ₯Ό μœ ν˜•μœΌλ‘œ μ‚¬μš©ν•˜λŠ” 것은 λΆˆκ°€λŠ₯ ν•΄ λ³΄μž…λ‹ˆλ‹€.
예λ₯Ό λ“€μ–΄ λ‹€μŒκ³Ό 같이 ꡬ성 μš”μ†Œ μΈμŠ€ν„΄μŠ€λ₯Ό λ³΄μœ ν•˜κΈ° μœ„ν•΄ μ €μž₯μ†Œλ₯Ό μž…λ ₯ ν•  수 μ—†μŠ΅λ‹ˆλ‹€.

import AnyComponent from "./AnyComponent"

const componentStore = writable<SvelteComponent>(null)

$componentStore = AnyComponent

λ§ˆμ§€λ§‰ 쀄은 λ‹€μŒ 였λ₯˜λ₯Ό μ œκ³΅ν•©λ‹ˆλ‹€.

μœ ν˜• 'typeof \

ꡬ성 μš”μ†Œλ₯Ό μž…λ ₯ν•˜λŠ” 방법에 λŒ€ν•΄ λ†“μΉœ 것이 λ‚˜μΌ μˆ˜λ„ μžˆμ§€λ§Œ 그런 μ’…λ₯˜μ˜ νŒ¨ν„΄μ„ μ‚¬μš©ν•  수 있기λ₯Ό λ°”λžλ‹ˆλ‹€.

λ‹€μŒμ€μ΄ 문제λ₯Ό μž‘μ„±ν•˜κΈ° 전에 μ—΄μ–΄ λ³Έ StackOverflow κ²Œμ‹œλ¬Όμž…λ‹ˆλ‹€ . @dummdidumm 이이 문제λ₯Ό μ—΄

Fixed bug

κ°€μž₯ μœ μš©ν•œ λŒ“κΈ€

μ•ˆλ…•ν•˜μ„Έμš” πŸ˜„
ν•œ κ°€μ§€λŠ” Svelte μ»΄ν¬λ„ŒνŠΈ 클래슀의 λ‚΄λΆ€ μ •μ˜μ— λŒ€ν•œ 일뢀 속성 / λ©”μ„œλ“œκ°€ λˆ„λ½λ˜μ—ˆλ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€. λ‹€λ₯Έ 것은 μž…λ ₯이 잘λͺ»λ˜μ—ˆλ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€. writable<typeof SvelteComponent> μ΄μ–΄μ•Όν•©λ‹ˆλ‹€. 그렇지 μ•ŠμœΌλ©΄ 클래슀 μœ ν˜•μ΄ μ•„λ‹Œ ν•΄λ‹Ή ꡬ성 μš”μ†Œμ˜ μΈμŠ€ν„΄μŠ€λ₯Ό μ°Έμ‘°ν•©λ‹ˆλ‹€.

λͺ¨λ“  6 λŒ“κΈ€

μ•ˆλ…•ν•˜μ„Έμš” πŸ˜„
ν•œ κ°€μ§€λŠ” Svelte μ»΄ν¬λ„ŒνŠΈ 클래슀의 λ‚΄λΆ€ μ •μ˜μ— λŒ€ν•œ 일뢀 속성 / λ©”μ„œλ“œκ°€ λˆ„λ½λ˜μ—ˆλ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€. λ‹€λ₯Έ 것은 μž…λ ₯이 잘λͺ»λ˜μ—ˆλ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€. writable<typeof SvelteComponent> μ΄μ–΄μ•Όν•©λ‹ˆλ‹€. 그렇지 μ•ŠμœΌλ©΄ 클래슀 μœ ν˜•μ΄ μ•„λ‹Œ ν•΄λ‹Ή ꡬ성 μš”μ†Œμ˜ μΈμŠ€ν„΄μŠ€λ₯Ό μ°Έμ‘°ν•©λ‹ˆλ‹€.

λΉ„μŠ·ν•œ λ¬Έμ œκ°€ λ°œμƒν–ˆμŠ΅λ‹ˆλ‹€.

import type { SvelteComponent } from 'svelte';
import Comp from './Comp.svelte';

const comp: SvelteComponent = Comp; // Type 'typeof SvelteComponentDev' is missing the following properties from type SvelteComponentDev: $set, $on, $destroy ...

v 3.35.0

λ¬Έμ œλŠ” κ°€μ Έμ˜¨ ꡬ성 μš”μ†Œκ°€ SvelteComponentDevκ°€ μ•„λ‹Œ "typeof SvelteComponentDev"μœ ν˜•μ„ κ°–λŠ” μ΄μœ μž…λ‹ˆλ‹€.

Comp λŠ” ν•΄λ‹Ή 클래슀의 μΈμŠ€ν„΄μŠ€κ°€ μ•„λ‹ˆλΌ 클래슀이기 λ•Œλ¬Έμž…λ‹ˆλ‹€.

class Foo {
    bar: string;
}

class Comp extends Foo {}

const comp: Foo = new Comp(); // OK
const compClass1: Foo = Comp; // WRONG
const compClass2: typeof Foo = Comp; // OK

μ•„. λ§μ΄λœλ‹€. κ°μ‚¬ν•©λ‹ˆλ‹€.

μ§€κΈˆ 이틀 λ™μ•ˆ 이걸둜 μ‹Έμš°κ³  μžˆμŠ΅λ‹ˆλ‹€. λ‚˜λŠ” 그것을 μ΄ν•΄ν•˜μ§€ λͺ»ν•œλ‹€.

<script lang="ts">
  import MyComponent from "./MyComponent.svelte";
  let myComponent: typeof MyComponent;
</script>

<MyComponent bind:this={myComponent}/> //Error here
Argument of type 'typeof MyComponent__SvelteComponent_' is not assignable to parameter of type 'MyComponent__SvelteComponent_'.   
Type 'typeof MyComponent__SvelteComponent_' is missing the following properties from type 'MyComponent__SvelteComponent_': $$prop_def, $$events_def, $$slot_def, $on, and 5 more.ts(2345)

λ‚΄κ°€ μ—¬κΈ°μ„œ 뭘 잘λͺ»ν•˜κ³  μžˆλ‹ˆ? κ·Έ μΈμŠ€ν„΄μŠ€λ₯Ό λ³€μˆ˜λ‘œ κ°€μ Έμ˜€κ³  μ‹ΆμŠ΅λ‹ˆλ‹€. 😭

@ Alfagun74 당신이 직면 ν•œ λ¬Έμ œλŠ”μ΄ μŠ€λ ˆλ“œμ˜ λ‹€λ₯Έ λ¬Έμ œμ™€ λ™μΌν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€. μ›ν•˜λŠ” 것은 클래슀의 μΈμŠ€ν„΄μŠ€μž…λ‹ˆλ‹€. λ”°λΌμ„œ λ‹€μŒμ΄ ν•„μš”ν•©λ‹ˆλ‹€.

<script lang="ts">
  import MyComponent from "./MyComponent.svelte";
  let myComponent: MyComponent;
</script>

<MyComponent bind:this={myComponent}/>

λ‹€λ₯Έ μ‚¬λžŒλ“€μ€ 동적 ꡬ성 μš”μ†Œλ₯Ό μ›ν•˜λ―€λ‘œ 클래슀 자체, 특수 ν•¨μˆ˜κ°€ ν•„μš”ν•©λ‹ˆλ‹€.

이 νŽ˜μ΄μ§€κ°€ 도움이 λ˜μ—ˆλ‚˜μš”?
0 / 5 - 0 λ“±κΈ‰