Skip to content
New issue

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

Allow using imported types in other types within the same file #8708

Merged

Conversation

annervisser
Copy link
Contributor

In the test case (from issue #7116) both the type definition and the import of the typed lived in the same file. This caused OpeningTypes to be an InlineTypeAlias instead of a LinkableTypeAlias, in turn causing an 'Invalid type alias' exception1

By replacing the array union (+) with an array_merge, the import of the type overrides the initial type declaration within the Main class. This means type imports within one file act more like they would when in separate files.

Fixes #7116

Footnotes

  1. src/Psalm/Type/Atomic.php:407

In the test case (from issue vimeo#7116) both the type definition and the
import of the typed lived in the same file. This caused `OpeningTypes`
to be an `InlineTypeAlias` instead of a `LinkableTypeAlias`, in turn
causing an 'Invalid type alias' exception[^1].

By replacing the array union (+) with an array_merge, the import of the
type overrides the initial type declaration within the `Main` class.
This means type imports within one file act more like they would when in
separate files.

Fixes vimeo#7116

[^1]: [src/Psalm/Type/Atomic.php:407](https://github.com/vimeo/psalm/blob/1986c8b4a8018b1819bc4b83b0f7e69c2c936792/src/Psalm/Type/Atomic.php#L407)
@annervisser annervisser force-pushed the allow-using-imported-type-in-other-type branch from 1874914 to d10b1f9 Compare November 15, 2022 13:46
@weirdan weirdan added the release:fix The PR will be included in 'Fixes' section of the release notes label Nov 15, 2022
@orklah
Copy link
Collaborator

orklah commented Nov 18, 2022

Thanks!

@orklah orklah merged commit 48c0df6 into vimeo:master Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:fix The PR will be included in 'Fixes' section of the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use imported type type cannot be used in template
3 participants