250x250
Rainbow๐ŸŒˆCoder
My dev Note๐Ÿ“’
Rainbow๐ŸŒˆCoder
์ „์ฒด ๋ฐฉ๋ฌธ์ž
์˜ค๋Š˜
์–ด์ œ
  • ๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ (411)
    • ๊ณต์ง€์‚ฌํ•ญ (0)
    • Debugger (10)
      • Visual Studio Debugger (1)
      • Chrome DevTools (3)
      • Visual Studio Code Debugger (4)
      • eclipse (1)
      • intelliJ (1)
    • OOP (2)
      • OOP (2)
    • TypeScript (54)
      • ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ TypeScript (54)
    • Javascript (87)
      • Javascript (45)
      • Node.js (19)
      • React (5)
      • FE ๊ฐœ๋ฐœํ™˜๊ฒฝ์„ค์ • (3)
      • React์™€ Node ๊ฐ™์ด ๋•Œ๋ ค์žก๊ธฐ (6)
      • next.js (2)
      • pixi.js (7)
    • ๋งˆํฌ์—… (23)
      • Html & Css (23)
    • C# (80)
      • C# (12)
      • ์ด๊ฒƒ์ด C#์ด๋‹ค (68)
    • C++ (30)
      • c++ (27)
      • win api (3)
    • Unity (18)
      • Unity(๊ธฐ์ดˆ) (8)
      • Unity(C#์ค‘๊ธ‰) (5)
      • ์œ ๋‹ˆํ‹ฐ ํฌํ†ค(๋„คํŠธ์›Œํฌ) (4)
      • unity c# MyCode (1)
    • Java & Spring (29)
      • Java (11)
      • ์Šคํ”„๋ง (8)
      • Java Algorithm (9)
      • Javs Data Structures (1)
    • ์ž๋ฃŒ๊ตฌ์กฐ์™€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ (15)
      • ์ž๋ฃŒ๊ตฌ์กฐ (5)
      • ์•Œ๊ณ ๋ฆฌ์ฆ˜ (10)
    • ํ˜•์ƒ๊ด€๋ฆฌ (15)
      • Git (11)
      • ์†Œ์ŠคํŠธ๋ฆฌ (3)
    • ๊ทธ๋ž˜ํ”ฝ์Šค (7)
      • WebGl (7)
    • AWS (3)
      • aws (3)
    • ๋ฆฌ๋ˆ…์Šค (5)
      • ๋ฆฌ๋ˆ…์Šค (5)
    • ์ฑ… ๋ฆฌ๋ทฐ (13)
      • ํด๋ฆฐ์ฝ”๋“œ(์ฑ…๋ฆฌ๋ทฐ) (3)
      • ์œ ์ง€๋ณด์ˆ˜๊ฐ€๋Šฅํ•œ์ฝ”๋”ฉ์˜๊ธฐ์ˆ C#ํŽธ(์ฑ…๋ฆฌ๋ทฐ) (1)
      • ๋ฆฌํŒฉํ† ๋ง(์ž๋ฐ”์Šคํฌ๋ฆฝํŠธํŒ) (9)
    • Server (2)
      • ๊ฒŒ์ž„ ์„œ๋ฒ„(๋„คํŠธ์›Œํฌ, ๋ฉ€ํ‹ฐ์“ฐ๋ ˆ๋“œ,OS) (2)
    • ์„ค๊ณ„, ์•„ํ‚คํ…์ณ (4)
    • ํŒŒ์ด์ฌ (5)
    • ๋””์ž์ธํŒจํ„ด (2)
    • mocha (2)
    • Jest (1)
    • Spine (1)
    • ์ธ๊ณต์ง€๋Šฅ (1)
      • ํ˜ผ์ž๊ณต๋ถ€ํ•˜๋Š”๋จธ์‹ ๋Ÿฌ๋‹+๋”ฅ๋Ÿฌ๋‹ (1)

๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

  • ํ™ˆ
  • ํƒœ๊ทธ
  • ๋ฐฉ๋ช…๋ก

๊ณต์ง€์‚ฌํ•ญ

์ธ๊ธฐ ๊ธ€

ํƒœ๊ทธ

  • ใ…ฃใ„ท
  • ์ปดํฌ์ง€์…˜
  • ์œ„์ž„
  • MySQL

์ตœ๊ทผ ๋Œ“๊ธ€

์ตœ๊ทผ ๊ธ€

ํ‹ฐ์Šคํ† ๋ฆฌ

hELLO ยท Designed By ์ •์ƒ์šฐ.
Rainbow๐ŸŒˆCoder

My dev Note๐Ÿ“’

TypeScript/ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ TypeScript

[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ! Non-null assertion operator

2022. 5. 2. 15:31
728x90
!: ์ด๋ž€?

๋А๋‚Œํ‘œ๋ฅผ ์ง€์šฐ๊ณ  ๋‚˜์˜ค๋Š” ์—๋Ÿฌ : 'ui'์€(๋Š”) ์ด๋‹ˆ์…œ๋ผ์ด์ €๊ฐ€ ์—†๊ณ  ์ƒ์„ฑ์ž์— ํ• ๋‹น๋˜์–ด ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค.ts(2564)
ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๊ฐ€ ํ˜น์‹œ null์ผ์ง€๋„ ๋ชจ๋ฅด๋Š” ๋Œ€์ƒ์— ์ปดํŒŒ์ผ์—๋Ÿฌ๋ผ์ธ ๋„์›Œ์ฃผ๋Š”๋ฐ
ํ”„๋กœ๊ทธ๋ž˜๋จธ๊ฐ€ null์ด ์•„๋‹ˆ๋ผ๊ณ  ํ™•์‹ ์ด ์žˆ์„๋•Œ์—
TSC Null์ฒดํฌ์— ์˜ˆ์™ธ ์ฒ˜๋ฆฌ ํ•ด์ฃผ๋Š” ๊ฒƒ
 
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator

Non-null assertion operator

A new ! post-fix expression operator may be used to assert that its operand is non-null and non-undefined in contexts where the type checker is unable to conclude that fact. Specifically, the operation x! produces a value of the type of x with null and undefined excluded. Similar to type assertions of the forms <T>x and x as T, the ! non-null assertion operator is simply removed in the emitted JavaScript code.

// Compiled with --strictNullChecks
function validateEntity(e?: Entity) {
// Throw exception if e is null or invalid entity
}
function processEntity(e?: Entity) {
validateEntity(e);
let s = e!.name; // Assert that e is non-null and access name
}

 

null์ด ์•„๋‹Œ ์–ด์„ค์…˜ ์—ฐ์‚ฐ์ž

์ƒˆ๋กœ์šด !ํ›„์œ„ ํ‘œํ˜„์‹ ์—ฐ์‚ฐ์ž๋Š” ์œ ํ˜• ๊ฒ€์‚ฌ๊ธฐ๊ฐ€ ํ•ด๋‹น ์‚ฌ์‹ค์„ ๊ฒฐ๋ก ์ง€์„ ์ˆ˜ ์—†๋Š” ์ปจํ…์ŠคํŠธ์—์„œ ํ”ผ์—ฐ์‚ฐ์ž๊ฐ€ null์ด ์•„๋‹ˆ๊ณ  ์ •์˜๋˜์ง€ ์•Š์Œ์„ ์ฃผ์žฅํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํŠนํžˆ ์ด ์ž‘์—… ์€ with ๋ฐ ์ œ์™ธ x!์œ ํ˜•์˜ ๊ฐ’์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค . ํ˜•์‹ ๋ฐ ์˜ ํ˜•์‹ ์–ด์„ค์…˜๊ณผ ์œ ์‚ฌํ•˜๊ฒŒ null ์ด ์•„๋‹Œ ์–ด์„ค์…˜ ์—ฐ์‚ฐ์ž๋Š” ๋‚ด๋ณด๋‚ด์ง„ JavaScript ์ฝ”๋“œ์—์„œ ๊ฐ„๋‹จํžˆ ์ œ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.xnullundefined<T>xx as T!

// Compiled with --strictNullChecks
function validateEntity(e?: Entity) {
// Throw exception if e is null or invalid entity
}
function processEntity(e?: Entity) {
validateEntity(e);
let s = e!.name; // Assert that e is non-null and access name
}

 

728x90

'TypeScript > ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ TypeScript' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ์œ ์šฉํ•œ ์ต์Šคํ…์…˜, Auto import  (0) 2022.05.05
[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] .d.ts ์— ๋Œ€ํ•œ ์ดํ•ด  (0) 2022.05.04
ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ + ๋ฆฌ๋•์Šค  (0) 2022.05.01
[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ํŒฉํ† ๋ฆฌ ํŒจํ„ด  (0) 2022.04.28
[ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ์—ฐ์Šต์šฉ์œผ๋กœ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ์„ธํŒ…  (0) 2022.04.27
    'TypeScript/ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ TypeScript' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
    • [ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ์œ ์šฉํ•œ ์ต์Šคํ…์…˜, Auto import
    • [ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] .d.ts ์— ๋Œ€ํ•œ ์ดํ•ด
    • ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ + ๋ฆฌ๋•์Šค
    • [ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ] ํŒฉํ† ๋ฆฌ ํŒจํ„ด
    Rainbow๐ŸŒˆCoder
    Rainbow๐ŸŒˆCoder
    ๋ชฐ๋ผ๋„ ๊ฒฐ๊ตญ์€ ์•„๋Š” ๊ฐœ๋ฐœ์ž, ๊ทธ๋Ÿฐ ์‚ฌ๋žŒ์ด ๋˜๊ธฐ ์œ„ํ•œ ๋งค์ผ์˜ ํ•œ๊ฑธ์Œ

    ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”