Skip to content

[bug:7.5.3] Mapper class explicite field regressionΒ #61540

Description

@jonlepage

πŸ”Ž Search Terms

Mapper class explicite inference for primitive

πŸ•— Version & Regression Information

  • This changed between versions 5.7.3 and 5.6.3

⏯ Playground Link

PLAYGROUND

if need, here is a very simple and epurate playground without all the tests.
SMALL_PLAYGROUND

πŸ’» Code

I have added some additional tests in order to gather more information and understand what is happening.
Bugs and fixes are the two adresse to verify.

declare function rollable( n:number ):number

export abstract class Abstract {
	[key: string]: number
	#Abstract!: never;
}

class Test {
	bug = new class {
		property1 = 1;
		property2 = rollable( 2 );
	}();

	fix = new class {
		property1:number = 1;
		property2 = rollable( 2 );
	}();

	moreBug1 = new class {
		property1 = 1 as const;
		property2 = rollable( 2 );
	}();

	moreBug2 = new class extends Abstract {
		property1 = 1 as const;
		property2 = rollable( 2 );
	}();
}
type Mapper<T> ={
	[k in keyof T]: [k, T[k]];
}
type Mapper2<T> ={
	[k in keyof T as string extends k ? never : k]: [k, T[k]];
}
type mapper_bug = Mapper<Test['bug']>; // work in version: 5.6.3
type mapper_fix = Mapper<Test['fix']>; // expected : property1: ["property1", number];
//       ^?
type mapper_moreTest1 = Mapper<Test['moreBug1']>;
type mapper_moreTest2 = Mapper<Test['moreBug2']>;
type mapper2_bug = Mapper2<Test['bug']>;
type mapper2_fix = Mapper2<Test['fix']>;

πŸ™ Actual behavior

the mapper ignore the field declaration !!

πŸ™‚ Expected behavior

the mapper should consider the field declaration !

Additional information about the issue

No, but I just spent a whole day trying to understand before realizing that it's a TypeScript issue! I am exhausted.

Image

please test the play ground in both version : 5.6.3 and 5.7.3

Activity

  1. changed the title [-][bug:7.5.3] Mapper class explicite inference for primitive[/-] [+][bug:7.5.3] Mapper class explicite field regression[/+] on Apr 6, 2025
  2. Andarist commented on Apr 7, 2025

    @Andarist
    Contributor

    Bisects to #59282

  3. RyanCavanaugh commented on Apr 8, 2025

    @RyanCavanaugh
    Member
    class C {
    	annotated: number = 1;
    	unannotated = 2;
    }
    type Mapper<T> = {
    	[k in keyof T]: k
    }
    type mapper_bug = Mapper<C>; // work in version: 5.6.3
    //    ^?
    //   Actual
    //   { annotated: "annotated"; unannotated: number }
    //   Expected
    //   { annotated: "annotated"; unannotated: "unannotated" }
  4. RyanCavanaugh commented on Sep 19, 2026

    @RyanCavanaugh
    Member

    This is fixed in the current native TypeScript build (7.1.0-dev.20260918.1).

    In TypeScript 5.7.3, Quick Info for Mapper<C> displays unannotated: number. The current build displays unannotated: ["unannotated", number], matching the annotated field's mapped tuple shape.

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: Mapped TypesThe issue relates to mapped typesFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions