Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ID-Prep] PR4 - Preserve types nodes from type assertions in declaration emit #57589

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 202 additions & 35 deletions src/compiler/transformers/declarations.ts

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion src/compiler/transformers/declarations/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
DiagnosticMessage,
Diagnostics,
ElementAccessExpression,
ExportAssignment,
ExpressionWithTypeArguments,
FunctionDeclaration,
GetAccessorDeclaration,
Expand All @@ -24,6 +25,7 @@ import {
isConstructorDeclaration,
isConstructSignatureDeclaration,
isElementAccessExpression,
isExportAssignment,
isExpressionWithTypeArguments,
isFunctionDeclaration,
isGetAccessor,
Expand Down Expand Up @@ -100,7 +102,8 @@ export type DeclarationDiagnosticProducing =
| BinaryExpression
| JSDocTypedefTag
| JSDocCallbackTag
| JSDocEnumTag;
| JSDocEnumTag
| ExportAssignment;

/** @internal */
export function canProduceDiagnostics(node: Node): node is DeclarationDiagnosticProducing {
Expand Down Expand Up @@ -231,9 +234,18 @@ export function createGetSymbolAccessibilityDiagnosticForNode(node: DeclarationD
else if (isTypeAliasDeclaration(node) || isJSDocTypeAlias(node)) {
return getTypeAliasDeclarationVisibilityError;
}
else if (isExportAssignment(node)) {
return getExportAssignmentTypeVisibilityDiagnosticMessage;
}
else {
return Debug.assertNever(node, `Attempted to set a declaration diagnostic context for unhandled node kind: ${Debug.formatSyntaxKind((node as Node).kind)}`);
}
function getExportAssignmentTypeVisibilityDiagnosticMessage() {
return {
diagnosticMessage: Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0,
errorNode: node,
};
}

function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccessibilityResult: SymbolAccessibilityResult) {
if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) {
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/coAndContraVariantInferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ interface Action<TName extends string, TPayload> {
name: TName;
payload: TPayload;
}
declare const actionA: Action<"ACTION_A", string>;
declare const actionB: Action<"ACTION_B", boolean>;
declare const actionA: Action<'ACTION_A', string>;
declare const actionB: Action<'ACTION_B', boolean>;
declare function call<TName extends string, TPayload>(action: Action<TName, TPayload>, fn: (action: Action<TName, TPayload>) => any): void;
declare const printFn: (action: typeof actionA | typeof actionB) => void;
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ var x = {};
//// [duplicatePropertiesInTypeAssertions01.d.ts]
declare let x: {
a: number;
a: number;
rbuckton marked this conversation as resolved.
Show resolved Hide resolved
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ var x = {};
//// [duplicatePropertiesInTypeAssertions02.d.ts]
declare let x: {
a: number;
a: number;
rbuckton marked this conversation as resolved.
Show resolved Hide resolved
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ hugeDeclarationOutputGetsTruncatedWithError.ts(5,14): error TS7056: The inferred

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

export const c = null as any as {[K in manyprops]: {[K2 in manyprops]: `${K}.${K2}`}};
export const c = () => null as any as {[K in manyprops]: {[K2 in manyprops]: `${K}.${K2}`}};
~
!!! error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ type props = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "

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

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

//// [hugeDeclarationOutputGetsTruncatedWithError.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.c = void 0;
exports.c = null;
var c = function () { return null; };
exports.c = c;
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ type manyprops = `${props}${props}`;
>props : Symbol(props, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 0, 0))
>props : Symbol(props, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 0, 0))

export const c = null as any as {[K in manyprops]: {[K2 in manyprops]: `${K}.${K2}`}};
export const c = () => null as any as {[K in manyprops]: {[K2 in manyprops]: `${K}.${K2}`}};
>c : Symbol(c, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 12))
>K : Symbol(K, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 34))
>K : Symbol(K, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 40))
>manyprops : Symbol(manyprops, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 0, 167))
>K2 : Symbol(K2, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 53))
>K2 : Symbol(K2, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 59))
>manyprops : Symbol(manyprops, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 0, 167))
>K : Symbol(K, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 34))
>K2 : Symbol(K2, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 53))
>K : Symbol(K, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 40))
>K2 : Symbol(K2, Decl(hugeDeclarationOutputGetsTruncatedWithError.ts, 4, 59))

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/baselines/reference/namedTupleMembers.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export declare const func: Func<SegmentAnnotated>;
export declare function useState<T>(initial: T): [value: T, setter: (T: any) => void];
export type Iter = Func<[step: number, iterations: number]>;
export declare function readSegment([length, count]: [number, number]): void;
export declare const val: [number, number];
export declare const val: Parameters<typeof readSegment>[0];
export type RecursiveTupleA = [initial: string, next: RecursiveTupleA];
export type RecursiveTupleB = [first: string, ptr: RecursiveTupleB];
export type RecusiveRest = [first: string, ...rest: RecusiveRest[]];
Expand Down
Loading
Loading