Here is a brief example outlining the TypeScript issue I am seeking help with:
export class Test {
public runTest<T>(param: T): T {
return param;
}
}
let test1: Test = new Test();
test1.runTest<string>("string1");
test1.runTest("5555");
Both calls to "runTest" will work without any errors. The first one expects a string as input (which is intended), but the second does not. I am looking for a solution to enforce passing a type into T whenever using the "runTest" method.
Is there a way to achieve this? I have tried various approaches in the code but haven't been successful. I also searched for a relevant TSLint rule but couldn't find one.
Thank you!