[Solved] Type ‘string’ is not assignable to type

Hello readers, Today In this article I am going to show you how to solve – Type ‘string’ is not assignable to type error in Java. So here I will explain all the possible solutions.

Without wasting your time, Let’s start This Article to Solve This Error.

How to Type ‘string’ is not assignable to type Occurs?

This is a common error to assign a string to a variable of custom type you might face while running a Java application. It looks as like below:

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 Error From the new ‘const‘ assertion So You need to Just Use const assertion Here is my example: let bike = “orange” as const; OR let bike = ‘orange’. Now, Your error must be solved.

  • Type ‘string’ is not assignable to type

To Solve Type ‘string’ is not assignable to type Error From the new ‘const‘ assertion So You need to Just Use const assertion Here is my example: let bike = “orange” as const; OR let bike = ‘orange’. Now, Your error must be solved.

Solution 1: Use const assertion

Since Typescript 3.4 introduced the new ‘const‘ assertion So You need to Just Use const assertion Here is my example.

let fruit = 'orange' as const;  // or...
let fruit = <const> 'orange';

Now, Your error will be solved.

Summary

It’s all About this issue. Hope all solutions helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Categories