Handle error when type parameter of mapped type uses private type

Fixes #30201
This commit is contained in:
Sheetal Nandi 2019-03-06 13:30:48 -08:00
parent d2364f555f
commit fe9f42480a
7 changed files with 77 additions and 0 deletions

View file

@ -2927,6 +2927,10 @@
"category": "Error",
"code": 4102
},
"Type parameter '{0}' of exported mapped object type is using private name '{1}'.": {
"category": "Error",
"code": 4103
},
"The current host does not support the '{0}' option.": {
"category": "Error",

View file

@ -391,6 +391,10 @@ namespace ts {
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
break;
case SyntaxKind.MappedType:
diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_mapped_object_type_is_using_private_name_1;
break;
case SyntaxKind.ConstructorType:
case SyntaxKind.ConstructSignature:
diagnosticMessage = Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;

View file

@ -0,0 +1,15 @@
/FromFactor.ts(2,15): error TS2304: Cannot find name 'StringKeyOf'.
/FromFactor.ts(2,15): error TS4103: Type parameter 'TName' of exported mapped object type is using private name 'StringKeyOf'.
==== /Helpers.ts (0 errors) ====
export type StringKeyOf<TObj> = Extract<string, keyof TObj>;
==== /FromFactor.ts (2 errors) ====
export type RowToColumns<TColumns> = {
[TName in StringKeyOf<TColumns>]: any;
~~~~~~~~~~~
!!! error TS2304: Cannot find name 'StringKeyOf'.
~~~~~~~~~~~
!!! error TS4103: Type parameter 'TName' of exported mapped object type is using private name 'StringKeyOf'.
}

View file

@ -0,0 +1,20 @@
//// [tests/cases/compiler/declarationEmitMappedPrivateTypeTypeParameter.ts] ////
//// [Helpers.ts]
export type StringKeyOf<TObj> = Extract<string, keyof TObj>;
//// [FromFactor.ts]
export type RowToColumns<TColumns> = {
[TName in StringKeyOf<TColumns>]: any;
}
//// [Helpers.js]
"use strict";
exports.__esModule = true;
//// [FromFactor.js]
"use strict";
exports.__esModule = true;
//// [Helpers.d.ts]
export declare type StringKeyOf<TObj> = Extract<string, keyof TObj>;

View file

@ -0,0 +1,16 @@
=== /Helpers.ts ===
export type StringKeyOf<TObj> = Extract<string, keyof TObj>;
>StringKeyOf : Symbol(StringKeyOf, Decl(Helpers.ts, 0, 0))
>TObj : Symbol(TObj, Decl(Helpers.ts, 0, 24))
>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --))
>TObj : Symbol(TObj, Decl(Helpers.ts, 0, 24))
=== /FromFactor.ts ===
export type RowToColumns<TColumns> = {
>RowToColumns : Symbol(RowToColumns, Decl(FromFactor.ts, 0, 0))
>TColumns : Symbol(TColumns, Decl(FromFactor.ts, 0, 25))
[TName in StringKeyOf<TColumns>]: any;
>TName : Symbol(TName, Decl(FromFactor.ts, 1, 5))
>TColumns : Symbol(TColumns, Decl(FromFactor.ts, 0, 25))
}

View file

@ -0,0 +1,10 @@
=== /Helpers.ts ===
export type StringKeyOf<TObj> = Extract<string, keyof TObj>;
>StringKeyOf : Extract<string, keyof TObj>
=== /FromFactor.ts ===
export type RowToColumns<TColumns> = {
>RowToColumns : RowToColumns<TColumns>
[TName in StringKeyOf<TColumns>]: any;
}

View file

@ -0,0 +1,8 @@
// @declaration: true
// @filename: /Helpers.ts
export type StringKeyOf<TObj> = Extract<string, keyof TObj>;
// @filename: /FromFactor.ts
export type RowToColumns<TColumns> = {
[TName in StringKeyOf<TColumns>]: any;
}