File tree 4 files changed +33
-0
lines changed
4 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,10 @@ title: Changelog
4
4
5
5
## Unreleased
6
6
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
+
7
11
## v0.28.4 (2025-05-04)
8
12
9
13
### Features
Original file line number Diff line number Diff line change @@ -792,6 +792,17 @@ const referenceConverter: TypeConverter<
792
792
return ref ;
793
793
}
794
794
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
+
795
806
let name : string ;
796
807
if ( ts . isIdentifier ( node . typeName ) ) {
797
808
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", () => {
2133
2133
const project = convert ( ) ;
2134
2134
equal ( query ( project , "Test" ) . type ?. toString ( ) , "() => Promise<any>" ) ;
2135
2135
} ) ;
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
+ } ) ;
2136
2143
} ) ;
You can’t perform that action at this time.
0 commit comments