Skip to content

5.0: An opaque type from other modules isn't inferred correctly #53581

Closed as not planned

Description

Bug Report

🔎 Search Terms

  • unique symbol
  • type inference
  • opaque

🕗 Version & Regression Information

  • This changed between versions v4.9.5 and v5.0.2
  • The nightly build also has the bug

⏯ Playground Link

Playground (v5.0.2)

💻 Code

declare const tag: unique symbol;
type Tagged<Token> = {
  readonly [tag]?: Token;
};
export type Opaque<Type, Token = unknown> = Type & Tagged<Token>;
export type Query<_V, _R> = Opaque<string>;

const q: Query<{}, {}> = 'query {}'

The opaque type that I borrowed from:

🙁 Actual behavior

The type of q is annotated correctly, Query<{}, {}> while the declaration of Query is on the same file. However, when I moved it to another file, the q is inferred as Query<_V, _R>. It is not reproduced on v4.9.5.

🙂 Expected behavior

The type of q should be inferred as Query<{}, {}> wherever the declaration of Query is located.

Activity

  1. RyanCavanaugh commented on Mar 30, 2023

    @RyanCavanaugh
    Member

    This looks like just a tooltip issue? The declaration emit shows {}, {} as expected.

  2. added
    Bug
    Domain: LS: Quick Info
    on Mar 30, 2023
  3. SeokminHong commented on Mar 31, 2023

    @SeokminHong
    Author

    Ryan Cavanaugh (@RyanCavanaugh) Could you try the following types?

    type PickVariable<T> = T extends Query<infer V, infer _R> ? V : never;
    type PickResponse<T> = T extends Query<infer _V, infer R> ? R : never;
    
    const v: PickVariable<Query<{}, {}>>;
    const r: PickResponse<Query<{}, {}>>;

    The v and r is inferred as {} on 4.9 but unknown on 5.0.

  4. whzx5byb commented on Mar 31, 2023

    @whzx5byb

    Even in the same file the behavior is bad in the nightly.

    declare const tag: unique symbol;
    type Tagged<Token> = {
      readonly [tag]?: Token;
    };
    export type Opaque<Type, Token = unknown> = Type & Tagged<Token>;
    export type Query<_V, _R> = Opaque<string>;
    
    const q: Query<{}, {}> = 'query {}'
    //    ^?
    // 5.1.0-dev.20230331: const q: Query<_V, _R>
    // 5.0.2: const q: Query<{}, {}>
  5. Andarist commented on Mar 31, 2023

    @Andarist
    Contributor

    The "same file" test case provided by whzx5byb can be bisected to: #53246

  6. locked as resolved and limited conversation to collaborators on Dec 3, 2025
  7. RyanCavanaugh commented on Dec 3, 2025

    @RyanCavanaugh
    Member

    Closing language service bugs related to the 6.0 implementation. For more information, see #62827

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    7.0 LS MigrationBugDomain: LS: Quick Info

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions