Skip to content

Preserve return type nodes which resolve to errors in declaration emit #58522

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

Merged
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
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8233,7 +8233,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function serializeReturnTypeForSignatureWorker(context: NodeBuilderContext, signature: Signature) {
const typePredicate = getTypePredicateOfSignature(signature);
const type = getReturnTypeOfSignature(signature);
if (!isErrorType(type) && context.enclosingDeclaration) {
if (context.enclosingDeclaration && (!isErrorType(type) || (context.flags & NodeBuilderFlags.AllowUnresolvedNames))) {
const annotation = signature.declaration && getNonlocalEffectiveReturnTypeAnnotationNode(signature.declaration);
const enclosingDeclarationIgnoringFakeScope = getEnclosingDeclarationIgnoringFakeScope(context.enclosingDeclaration);
if (!!findAncestor(annotation, n => n === enclosingDeclarationIgnoringFakeScope) && annotation) {
Expand Down
24 changes: 12 additions & 12 deletions tests/baselines/reference/asyncAwaitIsolatedModules_es2017.types
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function f1(): Promise<void> { }

async function f3(): MyPromise<void> { }
>f3 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

let f4 = async function() { }
>f4 : () => Promise<void>
Expand All @@ -39,9 +39,9 @@ let f5 = async function(): Promise<void> { }

let f6 = async function(): MyPromise<void> { }
>f6 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
>async function(): MyPromise<void> { } : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

let f7 = async () => { };
>f7 : () => Promise<void>
Expand All @@ -57,9 +57,9 @@ let f8 = async (): Promise<void> => { };

let f9 = async (): MyPromise<void> => { };
>f9 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
>async (): MyPromise<void> => { } : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

let f10 = async () => p;
>f10 : () => Promise<number>
Expand Down Expand Up @@ -87,17 +87,17 @@ let f12 = async (): Promise<number> => mp;

let f13 = async (): MyPromise<number> => p;
>f13 : () => MyPromise<number>
> : ^^^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
>async (): MyPromise<number> => p : () => MyPromise<number>
> : ^^^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
>p : Promise<number>
> : ^^^^^^^^^^^^^^^

let o = {
>o : { m1(): Promise<void>; m2(): Promise<void>; m3(): MyPromise<void>; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^
>{ async m1() { }, async m2(): Promise<void> { }, async m3(): MyPromise<void> { }} : { m1(): Promise<void>; m2(): Promise<void>; m3(): MyPromise<void>; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^

async m1() { },
>m1 : () => Promise<void>
Expand All @@ -109,7 +109,7 @@ let o = {

async m3(): MyPromise<void> { }
>m3 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

};

Expand All @@ -127,7 +127,7 @@ class C {

async m3(): MyPromise<void> { }
>m3 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

static async m4() { }
>m4 : () => Promise<void>
Expand All @@ -139,7 +139,7 @@ class C {

static async m6(): MyPromise<void> { }
>m6 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
}

module M {
Expand Down
24 changes: 12 additions & 12 deletions tests/baselines/reference/asyncAwaitIsolatedModules_es5.types
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function f1(): Promise<void> { }

async function f3(): MyPromise<void> { }
>f3 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

let f4 = async function() { }
>f4 : () => Promise<void>
Expand All @@ -39,9 +39,9 @@ let f5 = async function(): Promise<void> { }

let f6 = async function(): MyPromise<void> { }
>f6 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
>async function(): MyPromise<void> { } : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

let f7 = async () => { };
>f7 : () => Promise<void>
Expand All @@ -57,9 +57,9 @@ let f8 = async (): Promise<void> => { };

let f9 = async (): MyPromise<void> => { };
>f9 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
>async (): MyPromise<void> => { } : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

let f10 = async () => p;
>f10 : () => Promise<number>
Expand Down Expand Up @@ -87,17 +87,17 @@ let f12 = async (): Promise<number> => mp;

let f13 = async (): MyPromise<number> => p;
>f13 : () => MyPromise<number>
> : ^^^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
>async (): MyPromise<number> => p : () => MyPromise<number>
> : ^^^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
>p : Promise<number>
> : ^^^^^^^^^^^^^^^

let o = {
>o : { m1(): Promise<void>; m2(): Promise<void>; m3(): MyPromise<void>; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^
>{ async m1() { }, async m2(): Promise<void> { }, async m3(): MyPromise<void> { }} : { m1(): Promise<void>; m2(): Promise<void>; m3(): MyPromise<void>; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^

async m1() { },
>m1 : () => Promise<void>
Expand All @@ -109,7 +109,7 @@ let o = {

async m3(): MyPromise<void> { }
>m3 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

};

Expand All @@ -127,7 +127,7 @@ class C {

async m3(): MyPromise<void> { }
>m3 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

static async m4() { }
>m4 : () => Promise<void>
Expand All @@ -139,7 +139,7 @@ class C {

static async m6(): MyPromise<void> { }
>m6 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
}

module M {
Expand Down
24 changes: 12 additions & 12 deletions tests/baselines/reference/asyncAwaitIsolatedModules_es6.types
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function f1(): Promise<void> { }

async function f3(): MyPromise<void> { }
>f3 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

let f4 = async function() { }
>f4 : () => Promise<void>
Expand All @@ -39,9 +39,9 @@ let f5 = async function(): Promise<void> { }

let f6 = async function(): MyPromise<void> { }
>f6 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
>async function(): MyPromise<void> { } : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

let f7 = async () => { };
>f7 : () => Promise<void>
Expand All @@ -57,9 +57,9 @@ let f8 = async (): Promise<void> => { };

let f9 = async (): MyPromise<void> => { };
>f9 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
>async (): MyPromise<void> => { } : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

let f10 = async () => p;
>f10 : () => Promise<number>
Expand Down Expand Up @@ -87,17 +87,17 @@ let f12 = async (): Promise<number> => mp;

let f13 = async (): MyPromise<number> => p;
>f13 : () => MyPromise<number>
> : ^^^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
>async (): MyPromise<number> => p : () => MyPromise<number>
> : ^^^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
>p : Promise<number>
> : ^^^^^^^^^^^^^^^

let o = {
>o : { m1(): Promise<void>; m2(): Promise<void>; m3(): MyPromise<void>; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^
>{ async m1() { }, async m2(): Promise<void> { }, async m3(): MyPromise<void> { }} : { m1(): Promise<void>; m2(): Promise<void>; m3(): MyPromise<void>; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^

async m1() { },
>m1 : () => Promise<void>
Expand All @@ -109,7 +109,7 @@ let o = {

async m3(): MyPromise<void> { }
>m3 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

};

Expand All @@ -127,7 +127,7 @@ class C {

async m3(): MyPromise<void> { }
>m3 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^

static async m4() { }
>m4 : () => Promise<void>
Expand All @@ -139,7 +139,7 @@ class C {

static async m6(): MyPromise<void> { }
>m6 : () => MyPromise<void>
> : ^^^^^^^^^^^^^^^^^^^^^
> : ^^^^^^
}

module M {
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/badExternalModuleReference.types
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import a1 = require("garbage");

export declare var a: {
>a : { (): a1.connectExport; test1: a1.connectModule; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
> : ^^^^^^ ^^^^^^^^^ ^^^

test1: a1.connectModule;
>test1 : a1.connectModule
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/bluebirdStaticThis.types
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export declare class Promise<R> implements Promise.Thenable<R> {

static defer<R>(dit: typeof Promise): Promise.Resolver<R>;
>defer : <R>(dit: typeof Promise) => Promise.Resolver<R>
> : ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^
> : ^ ^^ ^^ ^^^^^
>dit : typeof Promise
> : ^^^^^^^^^^^^^^
>Promise : typeof Promise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ module TypeScriptAllInOne {
interface IF {
Foo(): bool;
>Foo : () => bool
> : ^^^^^^^^^^
> : ^^^^^^
}

class CLASS implements IF {
Expand Down Expand Up @@ -1323,7 +1323,7 @@ module TypeScriptAllInOne {
}
public Foo(): bool {
>Foo : () => bool
> : ^^^^^^^^^^
> : ^^^^^^

var myEvent = () => { return 1; };
>myEvent : () => number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ declare module "m2" {

function Z2(): X.I;
>Z2 : () => X.I
> : ^^^^^^^^^
> : ^^^^^^
>X : any
> : ^^^
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ declare module "m" {

export function bar(): X.bar; // error
>bar : () => X.bar
> : ^^^^^^^^^^^
> : ^^^^^^
>X : any
> : ^^^
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export declare function foo(): X.foo;

export declare function bar(): X.bar; // error
>bar : () => X.bar
> : ^^^^^^^^^^^
> : ^^^^^^
>X : any
> : ^^^

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function f(x: ()) {
>f : (x: () => any) => void
> : ^ ^^ ^^^^^^^^^
>x : () => any
> : ^^^^^^^^^
> : ^^^^^^
}

// Error (no '=>')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

=== functionVariableInReturnTypeAnnotation.ts ===
function bar(): typeof b {
>bar : () => any
> : ^^^^^^^^^
>bar : () => typeof b
> : ^^^^^^
>b : any
> : ^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ module TU {
>x : T
> : ^
>b : (x: U) => U
> : ^ ^^ ^^^^^^
> : ^ ^^ ^^^^^
>x : U
> : ^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ module TypeScript {
> : ^^^^^^^^^^^^^^^^^^^

static create<A,B,C>(arg1: any, arg2?: any, arg3?: any): MemberName {
>create : <A, B, C>(arg1: any, arg2?: any, arg3?: any) => any
> : ^^^^^^^^^^ ^^ ^^ ^^^ ^^ ^^^ ^^^^^^^^
>create : <A, B, C>(arg1: any, arg2?: any, arg3?: any) => MemberName
> : ^^^^^^^^^^ ^^ ^^ ^^^ ^^ ^^^ ^^^^^
>arg1 : any
> : ^^^
>arg2 : any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ declare var a: { x: C };
> : ^^^

declare var b: { (x: C): C };
>b : (x: C) => any
> : ^ ^^ ^^^^^^^^
>b : (x: C) => C
> : ^ ^^ ^^^^^
>x : any
> : ^^^

Expand All @@ -36,8 +36,8 @@ declare var d: { [x: C]: C };
> : ^^^

declare function f(x: C): C;
>f : (x: C) => any
> : ^ ^^ ^^^^^^^^
>f : (x: C) => C
> : ^ ^^ ^^^^^
>x : any
> : ^^^

Expand Down
Loading