Skip to content

Commit 9399b32

Browse files
Allow extraction of type from type assertions for declaration emit
1 parent 297ba1b commit 9399b32

19 files changed

+499
-179
lines changed

src/compiler/transformers/declarations.ts

Lines changed: 214 additions & 51 deletions
Large diffs are not rendered by default.

src/compiler/transformers/declarations/diagnostics.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
DiagnosticMessage,
1111
Diagnostics,
1212
ElementAccessExpression,
13+
ExportAssignment,
1314
ExpressionWithTypeArguments,
1415
FunctionDeclaration,
1516
GetAccessorDeclaration,
@@ -24,6 +25,7 @@ import {
2425
isConstructorDeclaration,
2526
isConstructSignatureDeclaration,
2627
isElementAccessExpression,
28+
isExportAssignment,
2729
isExpressionWithTypeArguments,
2830
isFunctionDeclaration,
2931
isGetAccessor,
@@ -100,7 +102,8 @@ export type DeclarationDiagnosticProducing =
100102
| BinaryExpression
101103
| JSDocTypedefTag
102104
| JSDocCallbackTag
103-
| JSDocEnumTag;
105+
| JSDocEnumTag
106+
| ExportAssignment;
104107

105108
/** @internal */
106109
export function canProduceDiagnostics(node: Node): node is DeclarationDiagnosticProducing {
@@ -231,9 +234,18 @@ export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationD
231234
else if (isTypeAliasDeclaration(node) || isJSDocTypeAlias(node)) {
232235
return getTypeAliasDeclarationVisibilityError;
233236
}
237+
else if (isExportAssignment(node)) {
238+
return getExportAssignmentTypeVisibilityDiagnosticMessage;
239+
}
234240
else {
235241
return Debug.assertNever(node, `Attempted to set a declaration diagnostic context for unhandled node kind: ${Debug.formatSyntaxKind((node as Node).kind)}`);
236242
}
243+
function getExportAssignmentTypeVisibilityDiagnosticMessage() {
244+
return {
245+
diagnosticMessage: Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0,
246+
errorNode: node,
247+
};
248+
}
237249

238250
function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) {
239251
if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) {
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
accessorDeclarationEmitVisibilityErrors.ts(2,18): error TS2304: Cannot find name 'DoesNotExist'.
2-
accessorDeclarationEmitVisibilityErrors.ts(2,18): error TS4106: Parameter 'arg' of accessor has or is using private name 'DoesNotExist'.
32

43

5-
==== accessorDeclarationEmitVisibilityErrors.ts (2 errors) ====
4+
==== accessorDeclarationEmitVisibilityErrors.ts (1 errors) ====
65
export class Q {
76
set bet(arg: DoesNotExist) {}
87
~~~~~~~~~~~~
98
!!! error TS2304: Cannot find name 'DoesNotExist'.
10-
~~~~~~~~~~~~
11-
!!! error TS4106: Parameter 'arg' of accessor has or is using private name 'DoesNotExist'.
129
}

tests/baselines/reference/accessorDeclarationEmitVisibilityErrors.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ export class Q {
99
export class Q {
1010
set bet(arg) { }
1111
}
12+
13+
14+
//// [accessorDeclarationEmitVisibilityErrors.d.ts]
15+
export declare class Q {
16+
set bet(arg: DoesNotExist);
17+
}

tests/baselines/reference/coAndContraVariantInferences.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ interface Action<TName extends string, TPayload> {
7070
name: TName;
7171
payload: TPayload;
7272
}
73-
declare const actionA: Action<"ACTION_A", string>;
74-
declare const actionB: Action<"ACTION_B", boolean>;
73+
declare const actionA: Action<'ACTION_A', string>;
74+
declare const actionB: Action<'ACTION_B', boolean>;
7575
declare function call<TName extends string, TPayload>(action: Action<TName, TPayload>, fn: (action: Action<TName, TPayload>) => any): void;
7676
declare const printFn: (action: typeof actionA | typeof actionB) => void;

tests/baselines/reference/duplicatePropertiesInTypeAssertions02.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ var x = {};
1010
//// [duplicatePropertiesInTypeAssertions02.d.ts]
1111
declare let x: {
1212
a: number;
13+
a: number;
1314
};

tests/baselines/reference/hugeDeclarationOutputGetsTruncatedWithError.errors.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ hugeDeclarationOutputGetsTruncatedWithError.ts(5,14): error TS7056: The inferred
66

77
type manyprops = `${props}${props}`;
88

9-
export const c = null as any as {[K in manyprops]: {[K2 in manyprops]: `${K}.${K2}`}};
9+
export const c = () => null as any as {[K in manyprops]: {[K2 in manyprops]: `${K}.${K2}`}};
1010
~
1111
!!! error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

tests/baselines/reference/hugeDeclarationOutputGetsTruncatedWithError.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ type props = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "
55

66
type manyprops = `${props}${props}`;
77

8-
export const c = null as any as {[K in manyprops]: {[K2 in manyprops]: `${K}.${K2}`}};
8+
export const c = () => null as any as {[K in manyprops]: {[K2 in manyprops]: `${K}.${K2}`}};
99

1010
//// [hugeDeclarationOutputGetsTruncatedWithError.js]
1111
"use strict";
1212
Object.defineProperty(exports, "__esModule", { value: true });
1313
exports.c = void 0;
14-
exports.c = null;
14+
var c = function () { return null; };
15+
exports.c = c;

tests/baselines/reference/hugeDeclarationOutputGetsTruncatedWithError.symbols

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ type manyprops = `${props}${props}`;
99
>props : Symbol(props, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 0, 0))
1010
>props : Symbol(props, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 0, 0))
1111

12-
export const c = null as any as {[K in manyprops]: {[K2 in manyprops]: `${K}.${K2}`}};
12+
export const c = () => null as any as {[K in manyprops]: {[K2 in manyprops]: `${K}.${K2}`}};
1313
>c : Symbol(c, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 12))
14-
>K : Symbol(K, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 34))
14+
>K : Symbol(K, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 40))
1515
>manyprops : Symbol(manyprops, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 0, 167))
16-
>K2 : Symbol(K2, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 53))
16+
>K2 : Symbol(K2, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 59))
1717
>manyprops : Symbol(manyprops, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 0, 167))
18-
>K : Symbol(K, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 34))
19-
>K2 : Symbol(K2, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 53))
18+
>K : Symbol(K, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 40))
19+
>K2 : Symbol(K2, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 59))
2020

tests/baselines/reference/hugeDeclarationOutputGetsTruncatedWithError.types

Lines changed: 3 additions & 2 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)