2

I'm getting [ts] 'imgNum' is declared but never used. for the following code where I'm trying to construct an image src string:

let imgNum: string = [...].toString();
imgSrc = '${imgNum}of5.png';

How do I get it not to raise the error when I'm actually using that value?

0

1 Answer 1

5

Sorry, but Typescript is right, you are not using the imgNum variable, you are assigning to imgSrc a string.

You want to use ` (backtick) instead of ' if you want to include the variable

let imgNum: string = [...].toString();
imgSrc = `${imgNum}of5.png`;

let imgNum = 2;
let imgSrc = '${imgNum}of5.png';
let imgSrc1 = `${imgNum}of5.png`;

console.log(imgSrc);
console.log(imgSrc1);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.