SO question

https://stackoverflow.com/questions/72488693/different-type-behaviour-while-using-function-vs-using-raw-code?noredirect=1#comment128052888_72488693
mail@pastecode.io avatar
unknown
typescript
2 years ago
327 B
0
Indexable
Never
function narrowUnknownTostring(rawParam: string | number): void {
  const narrowedParamError: string = rawParam; // Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'.
  rawParam = castString(rawParam);
  const narrowedParamOk: string = rawParam; // Everything's fine
}