π Search Terms
presence of export narrowing typescript typecheck type checking export statement
π Version & Regression Information
- This changed between versions 5.4.5 and 5.5.3
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.5.3#code/MYewdgzgLgBAHgLhgBQIYCcoEtUBsA8ASgKajoAm+YArgLYBGx6ANDAN6pLTpZgDmAXwB8QmAF52AgNwAoGbmKws4mAFZZWAGYAKOAG0sAXQCU7GTHgHDAOlQqA5AAtiuXCHuyLoSLE0r9RrIA9EEWYTAAegD8MgJyITBQ6ACeMNRgALSgtLTEYNj8iY5YEDC4vMQyCcRwAA4gmDDe0Glg6C6oUMTkACrFhRIALFJAA
π» Code
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;
π 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.
π 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
exportwas included.π Expected behavior
The
exportshould 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.