Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isolated declarations allows return types that reference local expr or type #58558

Closed
lucacasonato opened this issue May 17, 2024 · 0 comments Β· Fixed by #58620
Closed

Isolated declarations allows return types that reference local expr or type #58558

lucacasonato opened this issue May 17, 2024 · 0 comments Β· Fixed by #58620
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Domain: Isolated Declarations Related to the --isolatedDeclarations compiler flag

Comments

@lucacasonato
Copy link

πŸ”Ž 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

@lucacasonato lucacasonato changed the title Isolated declarations Isolated declarations allows return type that references local expr or type May 17, 2024
@lucacasonato lucacasonato changed the title Isolated declarations allows return type that references local expr or type Isolated declarations allows return types that references local expr or type May 17, 2024
@lucacasonato lucacasonato changed the title Isolated declarations allows return types that references local expr or type Isolated declarations allows return types that reference local expr or type May 17, 2024
@weswigham weswigham added Domain: Declaration Emit The issue relates to the emission of d.ts files Domain: Isolated Declarations Related to the --isolatedDeclarations compiler flag Bug A bug in TypeScript Recent Regression This is a new regression just found in the last major/minor version of TypeScript. and removed Domain: Isolated Declarations Related to the --isolatedDeclarations compiler flag Recent Regression This is a new regression just found in the last major/minor version of TypeScript. labels May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Declaration Emit The issue relates to the emission of d.ts files Domain: Isolated Declarations Related to the --isolatedDeclarations compiler flag
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants