File tree Expand file tree Collapse file tree 4 files changed +33
-0
lines changed
Expand file tree Collapse file tree 4 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ title: Changelog
44
55## Unreleased
66
7+ ### Bug Fixes
8+
9+ - References to type aliases defined as mapped types will now correctly create a reference to the type alias, #2954 .
10+
711## v0.28.4 (2025-05-04)
812
913### Features
Original file line number Diff line number Diff line change @@ -792,6 +792,17 @@ const referenceConverter: TypeConverter<
792792 return ref ;
793793 }
794794
795+ // #2954 mapped type aliases are special! The type that we have here will
796+ // not point at the type alias which names it like we want, but instead at
797+ // the mapped type instantiation. Fall back to converting via the original
798+ // type node to avoid creating a reference which points to the mapped type.
799+ if (
800+ originalNode && ts . isTypeReferenceNode ( originalNode ) && isObjectType ( type ) &&
801+ type . objectFlags & ts . ObjectFlags . Mapped
802+ ) {
803+ return referenceConverter . convert ( context , originalNode ) ;
804+ }
805+
795806 let name : string ;
796807 if ( ts . isIdentifier ( node . typeName ) ) {
797808 name = node . typeName . text ;
Original file line number Diff line number Diff line change 1+ export type AliasA = Readonly < Record < string , string > > ;
2+
3+ export type AliasB < T > = Readonly < Record < string , T > > ;
4+
5+ export type AliasC = Readonly < { } > ;
6+
7+ export interface InterfaceA {
8+ propertyA : AliasA ;
9+ propertyB : AliasB < string > ;
10+ propertyC : AliasC ;
11+ }
Original file line number Diff line number Diff line change @@ -2133,4 +2133,11 @@ describe("Issue Tests", () => {
21332133 const project = convert ( ) ;
21342134 equal ( query ( project , "Test" ) . type ?. toString ( ) , "() => Promise<any>" ) ;
21352135 } ) ;
2136+
2137+ it ( "#2954 handles Readonly with Record type" , ( ) => {
2138+ const project = convert ( ) ;
2139+ equal ( query ( project , "InterfaceA.propertyA" ) . type ?. toString ( ) , "AliasA" ) ;
2140+ equal ( query ( project , "InterfaceA.propertyB" ) . type ?. toString ( ) , "AliasB<string>" ) ;
2141+ equal ( query ( project , "InterfaceA.propertyC" ) . type ?. toString ( ) , "AliasC" ) ;
2142+ } ) ;
21362143} ) ;
You can’t perform that action at this time.
0 commit comments