티스토리 뷰
1. 파라미터 예외 처리가 이루어 지지 않음
function foo(bar: string) {
console.info(bar);
}
foo("Hello World!"); // OK
foo(null); // Error
foo(undefined); // Error
foo() // Error
2. | null 타입으로 null값을 허용한다. / undefined, 공백은 허용 x
function foo(bar: string | null) {
console.info(bar);
}
foo("Hello World!"); // OK
foo(null); // OK
foo(undefined); // Error
foo() // Error
3. | undefined 타입으로 undefined값을 허용한다 / null, 공백은 허용 x
function foo(bar: string | undefined) {
console.info(bar);
}
foo("Hello World!"); // OK
foo(null); // Error
foo(undefined); // OK
foo() // Error
4. null | undefined / 공백 허용 x
function foo(bar: string | null | undefined) {
console.info(bar);
}
foo("Hello World!"); // OK
foo(null); // OK
foo(undefined); // OK
foo() // Error
5. optional -> null 허용 x
function foo(bar?: string) {
console.info(bar);
}
foo("Hello World!"); // OK
foo(null); // Error
foo(undefined); // OK
foo() // OK
6. 짜잔! 평화가 찾아 왔다
function foo(bar?: string | null) {
console.info(bar);
}
foo("Hello World!"); // OK
foo(null); // OK
foo(undefined); // OK
foo() // OK
https://stackoverflow.com/questions/57243477/can-an-optional-parameter-be-null-in-typescript
Can an optional parameter be null in TypeScript?
According to this article, when strict null checking is enabled in TypeScript, you cannot assign null or undefined to a variable unless it is explicitly allowed with a union. // required value let...
stackoverflow.com
'javacsript > 공부' 카테고리의 다른 글
[cs 면접 공부 -1] (0) | 2023.07.30 |
---|---|
[js] 실행 컨텍스트 (0) | 2023.07.26 |
Active Record패턴과 Data Mapper 패턴 (0) | 2023.07.20 |
js 구조분해할당 [destructuring] (0) | 2023.07.11 |
js spread/rest 문법 (0) | 2023.07.11 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- react leva
- rollup react.js npm
- eslint
- react three fiber
- attempted import error: bvh_struct_definitions' is not exported from './gpu/bvhshaderglsl.js' (imported as 'bvhshaderglsl').
- react 3d text
- react 3d 에니메이션
- webpack glsl
- next.js glsl
- react 3d animation
- [leetcode] 394. decode string js
- leva
- typescript gsls
- three.js leva
- next.js import glsl
- react three fiber leva
- react glsl
- rollup typescript
- 394. decode string js
- ts glsl
- rollup ts react npm
- vue3
- 394 decode string
- [leetcode] 394. decode string
- vue
- react fiber 3d
- Vue.js
- react 3d
- rollup typescript react
- 394. decode string javascript
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
글 보관함