Open Seohyun-Roh opened 1 year ago
Thanks for the PR!
This section of the codebase is owned by @bumkeyy, @yeonjuan, @guyeol, and @dvlprsh - if they write a comment saying "LGTM" then it will be merged.
### Rest Parameters We can use optional parameters and overloads to accept a variety of definite arguments, but we _Indeterminate_ A function that accepts arguments of a number _Remaining parameters_can be defined using The remaining parameters appear after all other parameters. `...` syntax. ```ts twoslash function multiply(n: number, ...m: number[]) { return m.map((x) => n * x); } // 'a' gets value [10, 20, 30, 40] const a = multiply(10, 1, 2, 3, 4); ``` In TypeScript, type notation for these parameters is implicitly `any`Not `any[]`, and the type expression is `Array
You can use parameter decomposition to conveniently unpack the object supplied as an argument into one or more local variables in the function body. In JavaScript, it looks like the form below. ```js function sum({ a, b, c }) { console.log(a + b + c); } sum({ a: 10, b: 3, c: 9 }); ``` The type notation for the object is placed after the decomposition statement. ```ts twoslash function sum({ a, b, c }: { a: number; b: number; c: number }) { console.log(a + b + c); } ``` It may seem a bit wordy, but you can use any named type here as well. ```ts twoslash // 이전 예제와 동일 type ABC = { a: number; b: number; c: number }; function sum({ a, b, c }: ABC) { console.log(a + b + c); } ``` ## Assignmentability of functions ### `void` Return Type hydrous `void` Return types can cause some uncommon but predictable behavior. `void` Contextual typing into a return type returns nothing to the function **Avoid** Not forced **Is**Another way to explain this is, `void` A contextual function type with a return type (`type vf = () => void`) is implemented, _No value_or can be returned, but is ignored. Therefore, the type to be described later `() => void`are all valid. ```ts twoslash type voidFunc = () => void; const f1: voidFunc = () => { return true; }; const f2: voidFunc = () => true; const f3: voidFunc = function () { return true; }; ``` And when the return value of these functions is assigned to another variable, they still `void`will keep the type. ```ts twoslash type voidFunc = () => void; const f1: voidFunc = () => { return true; }; const f2: voidFunc = () => true; const f3: voidFunc = function () { return true; }; // ---cut--- const v1 = f1(); const v2 = f2(); const v3 = f3(); ``` Because this behavior exists, `Array.prototype.push`returns number, `Array.prototype.forEach` Method `void` Even if you expect a function with a return type, the following code might be valid: ```ts twoslash const src = [1, 2, 3]; const dst = [0]; src.forEach((el) => dst.push(el)); ``` There is one other case to keep in mind. If the literal function definition is `void` If it has a return value, the function should not return anything. **Not**. ```ts twoslash function f2(): void { // @ts-expect-error return true; } const f3 = function (): void { // @ts-expect-error return true; }; ``` `void`For more information, refer to the following document items. - [v1 handbook](https://www.typescriptlang.org/docs/handbook/basic-types.html#void) - [v2 handbook](https://www.typescriptlang.org/docs/handbook/2/functions.html#void) - [FAQ - "Why are functions returning non-void assignable to function returning void?"](https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-functions-returning-non-void-assignable-to-function-returning-void)배경지식 읽기:
구조분해 할당
Generated by :no_entry_sign: dangerJS against 93d4496f1b8abd3b89563ce2597c61305e3af164
Destructing -> Destructuring