After familiarizing myself with Typescript and understanding the concept of generic type T, I encountered an issue with a simple example. Can you pinpoint what's wrong?
function test1<string>(x:number):boolean{
let s:string="hello";
if (x==1 && s==="hello") return true
else return false
}
The compiler is showing an error: "Type parameter name cannot be 'string'". The problem lies within <string>
. In this code snippet, I'm attempting to define a non-generic type parameter, specifically for a <string>
.