π Search Terms
- isolated declarations
- typeof
- local types
- function return type
π Version & Regression Information
5.5.0-dev.20240517
β― Playground Link
https://www.typescriptlang.org/play/?target=99&isolatedDeclarations=true&ts=5.5.0-dev.20240517#code/MYewdgzgLgBAHjAvDARCg3AKAKZwA4gBOsAZgK5jBQCW4M42AFAJQwDemMXMh2UZhMOwC+MAIYQYUAJ55sIEvCzDMOfEVIUqtIVADuIFu07dQkWNKSoMJrr36CR4yTLkKY05atwFiMcpQ0dFAAFrxMrBzcUrLYMABaVtCE1GAA5ljR9gJCbKISCV5AA
π» Code
const x = "";
export function one() {
return {} as typeof x;
}
export function two() {
const y = "";
return {} as typeof y;
}
export function three() {
type Z = string;
return {} as Z;
}
π Actual behavior
No diagnostics are raised.
π Expected behavior
An isolated declarations error is raised for function two and function three (missing explicit return type), because even though both return an "explicit" type (using as casting), neither can be emitted without using a type checker because the type / expression they reference are internal to the function.
Additional information about the issue
I was looking for a case where this can happen top level, but I just ran into a different TypeScript error then: #58557
cc @dragomirtitian
π Search Terms
π Version & Regression Information
5.5.0-dev.20240517
β― Playground Link
https://www.typescriptlang.org/play/?target=99&isolatedDeclarations=true&ts=5.5.0-dev.20240517#code/MYewdgzgLgBAHjAvDARCg3AKAKZwA4gBOsAZgK5jBQCW4M42AFAJQwDemMXMh2UZhMOwC+MAIYQYUAJ55sIEvCzDMOfEVIUqtIVADuIFu07dQkWNKSoMJrr36CR4yTLkKY05atwFiMcpQ0dFAAFrxMrBzcUrLYMABaVtCE1GAA5ljR9gJCbKISCV5AA
π» Code
π Actual behavior
No diagnostics are raised.
π Expected behavior
An isolated declarations error is raised for function
twoand functionthree(missing explicit return type), because even though both return an "explicit" type (usingascasting), neither can be emitted without using a type checker because the type / expression they reference are internal to the function.Additional information about the issue
I was looking for a case where this can happen top level, but I just ran into a different TypeScript error then: #58557
cc @dragomirtitian