Skip to content

Type loosening regression with union types in TS 4.2 Β #43185

@Hurtak

Description

@Hurtak

Bug Report

πŸ”Ž Search Terms

  • union type

πŸ•— Version & Regression Information

  • bug exists in 4.2
  • works in 4.1

⏯ Playground Link

https://www.typescriptlang.org/play?target=5&jsx=0&ts=4.2.3#code/FAFwngDgpgBAogSxACygJwPIGsA8AlKAZwFcAbEAPhgF4YBvGcaALhgCI4BJAFQAk48AfQwBpNgG4YaImRCsCJcjBgBfUJFiIU6OGjQB7NDl0G0VWgyZRWHHvyEC8GPBKkzyrE4bVX4SVEYKsgA08HqG5n7amLhB5FQAPlEBXkapFMDAAMb6AHaEIDBQ-jrhaDQwONwUABTopqzcAJSeJWipVeZUNXTAAJBWNlx8AoKOzmzB-dKKckVlUypNmTn5hQBmxLlZAIwVNS3J6Di5xAC2AEbooRw7bF30-QD0TzDEhAi5AOYwqKTQ5U22xACDyMAu0gAhlhCIxUIwNDBPut0FBtlBQkgkbDkaiACYwSGwgpoT5faZQEDENC5IptVI1W5sZZqbJ5AowIFZABM+0OWgCJ3OVzQNzgdwevT6LxgeIQ0iyIFIYDcVJpZLhsH0FwAVlBFTAAO6GGEUtW0qUDDRDOyjcYuKZ9PozWRDO6OtSs1YcrkAZj5rWiQsu13Y4vuNCoUpl7w1AAMiTBvSA40aTYQzdTacVogymYTYcmWSt2RstlkACwBo7tMo4JmS56vQ2oWmx76amsdOBURPSc0I6CYtZQSEE-TrGv4UI9zGFSGkQj6NNoU3OylZum5sqM8MsmDAIA

When using union types with helper function constructing one of the type, the type is incorrectly loosened from string value type to string (func1). Directly returning the shape (func2) or using as const (func3) fixes it. Also when simplifying and removing the union (func4), it starts working.

This was not problem in 4.1, errors only in 4.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions