In the process of developing a project using Angular, I recently made the switch from VS Code to WebStorm. Unfortunately, I'm encountering some difficulties that I can't seem to make sense of. To ensure everything is functioning correctly, I performed several tests.
In one test, even though I specified the return type of the test()
function as a string
, I actually returned a boolean
. Surprisingly, no error was thrown. However, when I deliberately introduced an undeclared variable, it produced the wrong error message - stating an expected assignment instead of recognizing it as an undeclared variable. Subsequently, I proceeded to invoke the test()
function to see if it would generate the correct error upon execution. Unfortunately, it did not.
Take a look at the sample code below:
function test(): string {
return true;
}
bob;
bob = 1;
test();
https://i.sstatic.net/Ib5rH.png
Below is my TS.CONFIG file configuration:
{
"compileOnSave": false,
...
}
Also, here is the content of the TS.LINT file:
{
"extends": "tslint:recommended",
...
}
Edit:
I've encountered a significant issue with TypeScript in this scenario. Despite defining a parameter and specifying its type as a string, passing an integer as the argument did not trigger an error: