I want to know why errors occur, not how to get rid of them. I understand that I can use the as syntax to eliminate the error.
Please tell me why the error occurs. My understanding is that neither variable v2 nor v3 should have any elements that would prevent type identification. Variable v2 is definitely a variable of type string of PROMISE. Variable v3 is definitely an instance of class Hoge2. Please tell me why the error occurs because I want to learn typescript!
async function test() {
let v1: string | null = null;
while (true) {
const v2 = await hoge(v1);
const v3 = new Hoge2(v2);
v1 = v3.prop;
}
}
async function hoge(_: string | null){
return "";
}
class Hoge2{
constructor(private readonly _:any){}
get prop(){
return "";
}
}
'v2' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer
'v3' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.