인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

Rona's profile image
Rona

asked

[Renewal] TypeScript All-in-One: Part 1. Basic Grammar

Lowercase type 관련 질문

Resolved

Written on

·

100

0

안녕하세요.

[리뉴얼] 타입스크립트 올인원 강의를 듣고 있는데, "infer 타입 분석" 강좌에서 Lowercase type을 배웠습니다.

강의에서는 아래와 같이 해주면 에러가 안나던데 저는 ts2322 에러 Type 'string' is not assignable to type '"hello world"'. 가 발생합니다. ts version 은 5.5.4 입니다.

 

const words  = 'Hello World';
const lowerCaseWords: Lowercase<typeof words> = words.toLowerCase();

 

아래와 같이 타입단언으로 수정하면 에러가 안나는데, 다른 방법이 있을까요?

const words  = 'Hello World';
const lowerCaseWords = words.toLowerCase() as Lowercase<typeof words>;
typescript

Answer 1

0

zerocho님의 프로필 이미지
zerocho
Instructor

타입 단언으로 해야 하는 게 맞습니다!

Rona's profile image
Rona

asked

Ask a question