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

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

Open
jonlepage opened this issue Apr 6, 2025 Β· 2 comments
Open

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

jonlepage opened this issue Apr 6, 2025 Β· 2 comments
Assignees
Labels
Bug A bug in TypeScript

Comments

@jonlepage
Copy link

jonlepage commented Apr 6, 2025 β€’

πŸ”Ž 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

@jonlepage jonlepage changed the title [bug:7.5.3] Mapper class explicite inference for primitive [bug:7.5.3] Mapper class explicite field regression Apr 6, 2025
@Andarist
Copy link
Contributor

Andarist commented Apr 7, 2025

Bisects to #59282

@RyanCavanaugh
Copy link
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" }

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Apr 8, 2025
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.9.0 milestone Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants