Typescript Error - has no initializer and is not definately assigned in the constructor

Junghyun Park·2021년 8월 19일

문제 (오류 발생상황)

ref로 할당된 signRef를 클래스 컴포넌트에서 정의하려고 하면, 아래와 같은 오류 발생

해결

Definite Assignment Assertion

The definite assignment assertion is a feature that allows a ! to be placed after instance property and variable declarations to relay to TypeScript that a variable is indeed assigned for all intents and purposes, even if TypeScript’s analyses cannot detect so.

'!'를 instance 변수명에 추가하니 해결!

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html

profile
21c Carpenter

0개의 댓글