this my code
const y = "`${x()}${y()}`"
I get a warning Unexpected template string expression(no-template-curly-in-string).
how to get rid of the warning ?
You can escape the backticks, eg:
const y = `\`${x()}${y()}\``;
Related
I have a react code as shown below which prints the following o/p on console.
React Code:
if(type === "/page/chapter") {
console.log(trailFR); // Line A
}
Line A prints the following o/p on console:
/a2-fr
/a1-fr
/world-2020
Problem Statement:
I am wondering what changes I need to make in the react code above so that it prints the following output:
/chapters/a2-fr
/chapters/a1-fr
/chapters/world-2020
This is what I have tried but I am not getting the expecting output:
if(type === "/page/chapter") {
trailFR = {"/chapters"+trailFR}
console.log(trailFR); // Line A
}
You can do it in several ways
Template literal
console.log(`/chapters${trailFR}`)
or using String concatenation
console.log('/chapters'+trailFR)
or using concat method of a string
console.log('/chapters'.concat(trailFR.toString()))
I'm getting the error when I'm using '?'. What should i use instead?
The error is:
Module parse failed: Unexpected token You may need an appropriate loader to handle this file type.
const accessToken = user?.accessToken
if(accessToken){
const decodedAccessToken = decode(accessToken)
if(decodedAccessToken.exp * 1000 < new Date().getTime()){
console.log(decodedAccessToken.exp);
renewAccessToken(user.user._id)
}
}
I solved the problem. We have to use like this:
const accessToken = user ? user.accessToken : null;
I'm trying to set a string to be different things depending on an int, but when I declare a string in any if statement, even an always true one it seems to give me error: 'correctColor' undeclared (first use in this function).
If I have this line by itself, my code works fine.
char correctColor[] = "red";
But if I have something like
bool test = true;
if(test){
char correctColor[] = "red";
}
it gives me the error above. Any help is greatly appreciated.
Please see the comments below
bool test = true;
if(test){
char correctColor[] = "red";
// correctColor is available here until the end brace
}
// correctColor is not available here - it is now out of scope
Consider if test is false - Then correctColor would not be declared!
Assuming 'id' is a predefined dynamic variable; why would this not minify correctly?
var uniqueVariable = 'device_' + id;
$scope[uniqueVariable] = {uniqueVariable};
Here is the specific message from grunt-contrib-uglify:
Warning: Uglification failed.
Unexpected token punc «}», expected punc «:».
As Felippe Duarte pointed out, there needs to be a key-pair value, I can't just put any arbitrary string here like I had assumed.
I'm trying to use CoreVideo with Swift but I'm getting this error:
let flags : CVOptionFlags = 0
CVPixelBufferLockBaseAddress(imageBuffer, flags)
^~~~~~~~~~~~~~~~~
Cannot convert the expression's type 'CVReturn' to type 'CVPixelBuffer!'
CVPixelBufferLockBaseAddress(imageBuffer, 0)
^~~~~~~~~~~~~~~~~
Cannot convert the expression's type 'CVReturn' to type 'CVOptionFlags'
Why does it matter that it can't convert the value if I'm not using it anyways? Should I be passing the 2nd argument differently?
I guess it will be working.
var tmp : COpaquePointer = CMSampleBufferGetImageBuffer(imageBuffer).toOpaque()
var pixelBuf : CVPixelBuffer = (Unmanaged<CVPixelBuffer>.fromOpaque(tmp)).takeUnretainedValue()
CVPixelBufferLockBaseAddress(pixelBuf, 0)
I'm not very familiar with CoreVideo, but I guess the problem is more with imageBuffer init, as your first implementation seems correct.
This code works, at least compiles:
var pixelBuffer : CVPixelBuffer?
let optionFlags : CVOptionFlags = 0
CVPixelBufferLockBaseAddress(pixelBuffer, optionFlags)