Skip to content

Readable prevents type narrowing #2620

@luchsamapparat

Description

@luchsamapparat

openapi-fetch version

0.17.0

Description

After updating to openapi-fetch@0.17.0 and openapi-typescript@7.13.0 I get a type error when accessing a deeply nested property in combination with type narrowing. The original API model is rather complex and in parts driven by code generation requirements from the Java-based backend. However, it is a valid OpenAPI spec and everything worked fine until the update. I think it's the easiest if you take a look at the reproduction linked below.

I could narrow the issue down to the introduction of the Readable type. When I replace the Readable type in openapi-typescript-helpers with type Readable<T> = T everything works fine.

Reproduction

The original OpenAPI spec is from a complex insurance application. I tried to boil it down to the absolute minimum. Without the context it may seem like a rather contrived example, but you have to trust me that it's a valid use case 😉

https://github.com/luchsamapparat/openapi-typescript-readable-bug

Expected result

It should be possible to access tinyFooProp when narrowing the model down via ['@type'] === 'Foo'.

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-fetchRelevant to the openapi-fetch library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions