Hello Guys, How are you all? Hope You all Are Fine. Today I am trying to apply string to a variable of custom type But I am facing following error: Type ‘string’ is not assignable to type in Java. So Here I am Explain to you all the possible solutions here.
Without wasting your time, Let’s start This Article to Solve This Error.
How Type ‘string’ is not assignable to type Error Occurs ?
I am trying to apply string to a variable of custom type But I am facing following error.
Type 'string' is not assignable to type
How To Solve Type ‘string’ is not assignable to type Error ?
- How To Solve Type ‘string’ is not assignable to type Error ?
To Solve Type ‘string’ is not assignable to type ErrorFrom Typescript 3.4 introduced the new ‘const‘ assertion So You need to Just Use
const
assertion Here is my example: let bike = “Honda” as const; OR let bike = <const> ‘honda’; Now, Your error must be solved. - Type ‘string’ is not assignable to type
To Solve Type ‘string’ is not assignable to type ErrorFrom Typescript 3.4 introduced the new ‘const‘ assertion So You need to Just Use
const
assertion Here is my example: let bike = “Honda” as const; OR let bike = <const> ‘honda’; Now, Your error must be solved.
Solution 1: Use const
assertion
From Typescript 3.4 introduced the new ‘const‘ assertion So You need to Just Use const
assertion Here is my example.
let bike = "Honda" as const;
Or
let bike = <const> 'honda';
Now, Your error must be solved.
Summary
It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?
Also, Read