Skip to content

Presence of export affects narrowingΒ #59393

Closed
@nullromo

Description

@nullromo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions