Skip to content

Type alias substitution does not work #31616

Closed

Description

@reverofevil

TypeScript Version: 3.5.0-dev.20190525

Search Terms:
type substitution is incorrect

Code

const v = { test: { smth: 5 } };
type Field<A extends string, R> = { [K in A]: R } | {}
const f = <A extends string, B extends string, R>(x: { [K in A]: Field<B, R> } | {}): R => ({} as any);
const g = <A extends string, B extends string, R>(x: Field<A, Field<B, R>>): R => ({} as any);
const r1 = f(v); // number
const r2 = g(v); // unknown

Expected behavior:
Both should be number.

Actual behavior:
unknown

Playground Link:
Link

Related Issues:
Nope.

Activity

  1. RyanCavanaugh commented on May 28, 2019

    @RyanCavanaugh
    Member

    Regressed between 2.3 and 2.4

    Removed suspect | {}:

    const v = { test: { smth: 5 } };
    type Field<A extends string, R> = { [K in A]: R };
    const f = <A extends string, B extends string, R>(x: { [K in A]: Field<B, R> } ): R => ({} as any);
    const g = <A extends string, B extends string, R>(x: Field<A, Field<B, R>>): R => ({} as any);
    const r1 = f(v); // number
    const r2 = g(v); // unknown
  2. weswigham commented on May 28, 2019

    @weswigham
    Member

    Regression caused by #15863 - potential fix is up at #31633 - I need to run RWC to validate fp-ts doesn't OOM (which was what originally prompted the original change that caused the regression), since the change introducing the regression didn't come with any baked-in tests ❤️

  3. added
    BugA bug in TypeScript
    Domain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolution
    and removed
    Needs InvestigationThis issue needs a team member to investigate its status.
    on May 28, 2019
  4. 23 remaining items

  5. RyanCavanaugh commented on Feb 14, 2023

    @RyanCavanaugh
    Member

    These are both number now as expected

  6. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: check: Type InferenceRelated to type inference performed during signature resolution or `infer` type resolutionFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions