Skip to content

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

Open
@jonlepage

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

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions