Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fe9f424

Browse filesBrowse files
committed
Handle error when type parameter of mapped type uses private type
Fixes microsoft#30201
1 parent d2364f5 commit fe9f424
Copy full SHA for fe9f424

7 files changed

+77Lines changed: 77 additions & 0 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/diagnosticMessages.json‎

Copy file name to clipboardExpand all lines: src/compiler/diagnosticMessages.json
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,6 +2927,10 @@
29272927
"category": "Error",
29282928
"code": 4102
29292929
},
2930+
"Type parameter '{0}' of exported mapped object type is using private name '{1}'.": {
2931+
"category": "Error",
2932+
"code": 4103
2933+
},
29302934

29312935
"The current host does not support the '{0}' option.": {
29322936
"category": "Error",
Collapse file

‎src/compiler/transformers/declarations/diagnostics.ts‎

Copy file name to clipboardExpand all lines: src/compiler/transformers/declarations/diagnostics.ts
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,10 @@ namespace ts {
391391
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
392392
break;
393393

394+
case SyntaxKind.MappedType:
395+
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_mapped_object_type_is_using_private_name_1;
396+
break;
397+
394398
case SyntaxKind.ConstructorType:
395399
case SyntaxKind.ConstructSignature:
396400
diagnosticMessage = Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
Collapse file
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/FromFactor.ts(2,15): error TS2304: Cannot find name 'StringKeyOf'.
2+
/FromFactor.ts(2,15): error TS4103: Type parameter 'TName' of exported mapped object type is using private name 'StringKeyOf'.
3+
4+
5+
==== /Helpers.ts (0 errors) ====
6+
export type StringKeyOf<TObj> = Extract<string, keyof TObj>;
7+
8+
==== /FromFactor.ts (2 errors) ====
9+
export type RowToColumns<TColumns> = {
10+
[TName in StringKeyOf<TColumns>]: any;
11+
~~~~~~~~~~~
12+
!!! error TS2304: Cannot find name 'StringKeyOf'.
13+
~~~~~~~~~~~
14+
!!! error TS4103: Type parameter 'TName' of exported mapped object type is using private name 'StringKeyOf'.
15+
}
Collapse file
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [tests/cases/compiler/declarationEmitMappedPrivateTypeTypeParameter.ts] ////
2+
3+
//// [Helpers.ts]
4+
export type StringKeyOf<TObj> = Extract<string, keyof TObj>;
5+
6+
//// [FromFactor.ts]
7+
export type RowToColumns<TColumns> = {
8+
[TName in StringKeyOf<TColumns>]: any;
9+
}
10+
11+
//// [Helpers.js]
12+
"use strict";
13+
exports.__esModule = true;
14+
//// [FromFactor.js]
15+
"use strict";
16+
exports.__esModule = true;
17+
18+
19+
//// [Helpers.d.ts]
20+
export declare type StringKeyOf<TObj> = Extract<string, keyof TObj>;
Collapse file
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== /Helpers.ts ===
2+
export type StringKeyOf<TObj> = Extract<string, keyof TObj>;
3+
>StringKeyOf : Symbol(StringKeyOf, Decl(Helpers.ts, 0, 0))
4+
>TObj : Symbol(TObj, Decl(Helpers.ts, 0, 24))
5+
>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --))
6+
>TObj : Symbol(TObj, Decl(Helpers.ts, 0, 24))
7+
8+
=== /FromFactor.ts ===
9+
export type RowToColumns<TColumns> = {
10+
>RowToColumns : Symbol(RowToColumns, Decl(FromFactor.ts, 0, 0))
11+
>TColumns : Symbol(TColumns, Decl(FromFactor.ts, 0, 25))
12+
13+
[TName in StringKeyOf<TColumns>]: any;
14+
>TName : Symbol(TName, Decl(FromFactor.ts, 1, 5))
15+
>TColumns : Symbol(TColumns, Decl(FromFactor.ts, 0, 25))
16+
}
Collapse file
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== /Helpers.ts ===
2+
export type StringKeyOf<TObj> = Extract<string, keyof TObj>;
3+
>StringKeyOf : Extract<string, keyof TObj>
4+
5+
=== /FromFactor.ts ===
6+
export type RowToColumns<TColumns> = {
7+
>RowToColumns : RowToColumns<TColumns>
8+
9+
[TName in StringKeyOf<TColumns>]: any;
10+
}
Collapse file
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @declaration: true
2+
// @filename: /Helpers.ts
3+
export type StringKeyOf<TObj> = Extract<string, keyof TObj>;
4+
5+
// @filename: /FromFactor.ts
6+
export type RowToColumns<TColumns> = {
7+
[TName in StringKeyOf<TColumns>]: any;
8+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.