We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
export
presence of export narrowing typescript typecheck type checking export statement
https://www.typescriptlang.org/play/?ts=5.5.3#code/MYewdgzgLgBAHgLhgBQIYCcoEtUBsA8ASgKajoAm+YArgLYBGx6ANDAN6pLTpZgDmAXwB8QmAF52AgNwAoGbmKws4mAFZZWAGYAKOAG0sAXQCU7GTHgHDAOlQqA5AAtiuXCHuyLoSLE0r9RrIA9EEWYTAAegD8MgJyITBQ6ACeMNRgALSgtLTEYNj8iY5YEDC4vMQyCcRwAA4gmDDe0Glg6C6oUMTkACrFhRIALFJAA
const x: Partial<Record<number, {a: string}>> = {}; let i = 5; if(x[i]) { x[i].a = 'hello'; } // try un-commenting this line // export const unrelatedThing = 4;
The type narrowing for an index type did not work unless an export was included.
The export should not affect the compilation or typechecking of a file at all.
This could possibly be a bug with just the TS playground; I did not test it on my machine.
The text was updated successfully, but these errors were encountered:
As an additional note, if you change let to const, then there is no error. The problematic behavior only occurs with let.
let
const
Sorry, something went wrong.
Behavior is intentional; implemented in #57847, and see #58972
Hmmm, okay. This comment summarizes it well. Adding export actually encapsulates the file, making static analysis possible.
No branches or pull requests
π Search Terms
presence of export narrowing typescript typecheck type checking export statement
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.5.3#code/MYewdgzgLgBAHgLhgBQIYCcoEtUBsA8ASgKajoAm+YArgLYBGx6ANDAN6pLTpZgDmAXwB8QmAF52AgNwAoGbmKws4mAFZZWAGYAKOAG0sAXQCU7GTHgHDAOlQqA5AAtiuXCHuyLoSLE0r9RrIA9EEWYTAAegD8MgJyITBQ6ACeMNRgALSgtLTEYNj8iY5YEDC4vMQyCcRwAA4gmDDe0Glg6C6oUMTkACrFhRIALFJAA
π» Code
π Actual behavior
The type narrowing for an index type did not work unless an
export
was included.π Expected behavior
The
export
should not affect the compilation or typechecking of a file at all.Additional information about the issue
This could possibly be a bug with just the TS playground; I did not test it on my machine.
The text was updated successfully, but these errors were encountered: