TypeScript ๋ฒ์ :
์ผ๊ฐ (1.9.0-dev.20160217)
์ํธ
export interface QueryMetadataFactory {
(selector: Type | string, {descendants, read}?: {
descendants?: boolean;
read?: any;
}): ParameterDecorator;
new (selector: Type | string, {descendants, read}?: {
descendants?: boolean;
read?: any;
}): QueryMetadata;
}
์์๋๋ ๋์ :
์๊ฒฉํ null ๊ฒ์ฌ๋ก ์ด๊ฒ์ ์ปดํ์ผ ํ ๋ ๊ตฌ์กฐํ๋์ง ์์ ๋ณ์๊ฐ ์ ํ ์ฌํญ์ผ๋ก ํ์ ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ด ์ปดํ์ผ ๋ ๊ฒ์ผ๋ก ์์ํฉ๋๋ค.
export interface QueryMetadataFactory {
(selector: Type | string, whatever?: {
descendants?: boolean;
read?: any;
}): ParameterDecorator;
new (selector: Type | string, whatever?: {
descendants?: boolean;
read?: any;
}): QueryMetadata;
}
์ค์ ํ๋ :
์ปดํ์ผ์ :
node_modules/@angular/core/src/metadata.d.ts(356,32): error TS2459: Type '{ descendants?: boolean | undefined; read?: any; } | undefined' has no property 'descendants' and no string index signature.
node_modules/@angular/core/src/metadata.d.ts(356,45): error TS2459: Type '{ descendants?: boolean | undefined; read?: any; } | undefined' has no property 'read' and no string index signature.
node_modules/@angular/core/src/metadata.d.ts(360,36): error TS2459: Type '{ descendants?: boolean | undefined; read?: any; } | undefined' has no property 'descendants' and no string index signature.
node_modules/@angular/core/src/metadata.d.ts(360,49): error TS2459: Type '{ descendants?: boolean | undefined; read?: any; } | undefined' has no property 'read' and no string index signatu
์ด๊ฒ์ ๊ฒฝ๊ณ์ ์ ๋๋ค. ํจ์
function foo({ a, b }?: { a: number, b: number }) {
}
๊ตฌ์กฐ๋ฅผ ํด์ ํ๋ ค๋ ์ธ์๊ฐ undefined
์ ์๊ธฐ ๋๋ฌธ์ ์ค์ ๋ก ์ค๋ฅ์
๋๋ค. ๋ฐ๋ผ์ ์์ ์์๋ ์ ํํ ์๋ช
์ ๊ตฌํํ๋ ๊ฒ์ ๋ถ๊ฐ๋ฅํฉ๋๋ค. ์ด์ ์ ์ธ์ ๋ค์๊ณผ ๊ฐ์ด ๋ณ๊ฒฝํ๋ฉด
function foo({ a, b }: { a: number, b: number } = { a: 0, b: 0 }) {
}
undefined
๊ฐ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ๋์ฒด๋๋ฏ๋ก ๋ ์ด์ ์ค๋ฅ๊ฐ ์๋๋๋ค. ๊ทธ๋ฌ๋ ํธ์ถ์์ ๊ด์ ์์ ๋งค๊ฐ ๋ณ์๋ ์ฌ์ ํ ์ ํ ์ฌํญ์ด๋ฉฐ ์ด์ ์ ์ธ ํ์ผ์ ์์ฑํ๋ฉด ์ ์ธ์ ๋ฑ์ด๋
๋๋ค.
declare function foo({ a, b }?: { a: number, b: number }): void;
์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ _that_์ ๋ฒ๊ทธ์ ๋๋ค.
์ ์ณ๋๊ณ ๋น ๊ตฌํ ์๊ทธ๋์ฒ์์ ๋น ๊ตฌ์กฐํ ๋งค๊ฐ ๋ณ์๋ฅผ ํผํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ๊ทธ๊ฒ๋ค์ ์ค์ ๋ก ๊ตฌํ ์ธ๋ถ ์ฌํญ์ ๋๋ค. ์ฆ, ํจ์ ๊ตฌํ์ด ์ธ์๋ฅผ ๊ตฌ์กฐํํ๋์ง ๋๋ ์์ฑ ์ก์ธ์ค๋ฅผ ์ฌ์ฉํ๋์ง ์ฌ๋ถ๋ ํธ์ถ์์๊ฒ ์ค์ ๋ก ๋ฌธ์ ๊ฐ๋์ง ์์์ผํฉ๋๋ค. ๊ทธ๋ฌ๋ ์ ์ธ ํ์ผ์ ๊ฒฝ์ฐ ๋ฐฉ์ถ ํ ์ค์ ๋งค๊ฐ ๋ณ์ ์ด๋ฆ์ด ์๊ธฐ ๋๋ฌธ์ (๋ง์ง ๋ชปํด) ๋น ๊ตฌ์กฐํ ํจํด์ ๋ฐฉ์ถํ๋ฏ๋ก ๋ฒ๊ทธ๋ฅผ ์์ ํด์ผํฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด๊ฒ์ ๊ฒฝ๊ณ์ ์ ๋๋ค. ํจ์
๊ตฌ์กฐ๋ฅผ ํด์ ํ๋ ค๋ ์ธ์๊ฐ
undefined
์ ์๊ธฐ ๋๋ฌธ์ ์ค์ ๋ก ์ค๋ฅ์ ๋๋ค. ๋ฐ๋ผ์ ์์ ์์๋ ์ ํํ ์๋ช ์ ๊ตฌํํ๋ ๊ฒ์ ๋ถ๊ฐ๋ฅํฉ๋๋ค. ์ด์ ์ ์ธ์ ๋ค์๊ณผ ๊ฐ์ด ๋ณ๊ฒฝํ๋ฉดundefined
๊ฐ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ๋์ฒด๋๋ฏ๋ก ๋ ์ด์ ์ค๋ฅ๊ฐ ์๋๋๋ค. ๊ทธ๋ฌ๋ ํธ์ถ์์ ๊ด์ ์์ ๋งค๊ฐ ๋ณ์๋ ์ฌ์ ํ ์ ํ ์ฌํญ์ด๋ฉฐ ์ด์ ์ ์ธ ํ์ผ์ ์์ฑํ๋ฉด ์ ์ธ์ ๋ฑ์ด๋ ๋๋ค.์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ _that_์ ๋ฒ๊ทธ์ ๋๋ค.
์ ์ณ๋๊ณ ๋น ๊ตฌํ ์๊ทธ๋์ฒ์์ ๋น ๊ตฌ์กฐํ ๋งค๊ฐ ๋ณ์๋ฅผ ํผํ๋ ๊ฒ์ด ์ข์ต๋๋ค. ๊ทธ๊ฒ๋ค์ ์ค์ ๋ก ๊ตฌํ ์ธ๋ถ ์ฌํญ์ ๋๋ค. ์ฆ, ํจ์ ๊ตฌํ์ด ์ธ์๋ฅผ ๊ตฌ์กฐํํ๋์ง ๋๋ ์์ฑ ์ก์ธ์ค๋ฅผ ์ฌ์ฉํ๋์ง ์ฌ๋ถ๋ ํธ์ถ์์๊ฒ ์ค์ ๋ก ๋ฌธ์ ๊ฐ๋์ง ์์์ผํฉ๋๋ค. ๊ทธ๋ฌ๋ ์ ์ธ ํ์ผ์ ๊ฒฝ์ฐ ๋ฐฉ์ถ ํ ์ค์ ๋งค๊ฐ ๋ณ์ ์ด๋ฆ์ด ์๊ธฐ ๋๋ฌธ์ (๋ง์ง ๋ชปํด) ๋น ๊ตฌ์กฐํ ํจํด์ ๋ฐฉ์ถํ๋ฏ๋ก ๋ฒ๊ทธ๋ฅผ ์์ ํด์ผํฉ๋๋ค.