TypeScript ๋ฒ์ :
์ผ๊ฐ (1.9.0-dev.20160217)
์ํธ
class Example {
get foo() {
return true;
}
baz(example: Example) {
example.foo;
}
bar(example: Example | Object) {
example.foo; // error TS2339: Property 'foo' does not exist on type 'Example | Object'.
}
}
์์๋๋ ๋์ :
example.foo
๋ ๋ ๋ฐฉ๋ฒ ๋ชจ๋์์ ์ค๋ฅ๋ฅผ ๋ฐ์์ํค์ง ์์ต๋๋ค.
์ค์ ํ๋ :
example.foo
example
์ด Example | Object
๋ example
error TS2339: Property 'foo' does not exist on type 'Example | Object'.
์ด๊ฒ์ .foo
๊ฐ ์์ ์๋์๋ ๊ฒ์ ๋ํด ๋น์ ์ ๋ณดํธํ๋ TypeScript์ ์ ์์ ์ธ ๋์์
๋๋ค.
์ด ์์
์ ์ํํ๋ ค๋ฉด .foo
๊ฐ ํฌํจ ๋ ํญ๋ชฉ์ผ๋ก ์ ํ ์
class Example {
get foo() {
return true;
}
baz(example: Example) {
example.foo;
}
bar(example: Example | Object) {
if (example instanceof Example) {
example.foo;
}
}
}
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด๊ฒ์
.foo
๊ฐ ์์ ์๋์๋ ๊ฒ์ ๋ํด ๋น์ ์ ๋ณดํธํ๋ TypeScript์ ์ ์์ ์ธ ๋์์ ๋๋ค.์ด ์์ ์ ์ํํ๋ ค๋ฉด
.foo
๊ฐ ํฌํจ ๋ ํญ๋ชฉ์ผ๋ก ์ ํ ์