diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1673c6c032716..740e7bed54dd0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -25513,7 +25513,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { case SyntaxKind.ArrowFunction: if (noImplicitAny && !(declaration as NamedDeclaration).name) { if (wideningKind === WideningKind.GeneratorYield) { - error(declaration, Diagnostics.Generator_implicitly_has_yield_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type_annotation, typeAsString); + error(declaration, Diagnostics.Generator_implicitly_has_yield_type_0_Consider_supplying_a_return_type_annotation, typeAsString); } else { error(declaration, Diagnostics.Function_expression_which_lacks_return_type_annotation_implicitly_has_an_0_return_type, typeAsString); @@ -25535,12 +25535,40 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { errorOrSuggestion(noImplicitAny, declaration, diagnostic, declarationNameToString(getNameOfDeclaration(declaration)), typeAsString); } + function shouldReportErrorsFromWideningWithContextualSignature(declaration: FunctionLikeDeclaration, wideningKind: WideningKind) { + const signature = getContextualSignatureForFunctionLikeDeclaration(declaration); + if (!signature) { + return true; + } + let returnType = getReturnTypeOfSignature(signature); + const flags = getFunctionFlags(declaration); + switch (wideningKind) { + case WideningKind.FunctionReturn: + if (flags & FunctionFlags.Generator) { + returnType = getIterationTypeOfGeneratorFunctionReturnType(IterationTypeKind.Return, returnType, !!(flags & FunctionFlags.Async)) ?? returnType; + } + else if (flags & FunctionFlags.Async) { + returnType = getAwaitedTypeNoAlias(returnType) ?? returnType; + } + return isGenericType(returnType); + case WideningKind.GeneratorYield: + const yieldType = getIterationTypeOfGeneratorFunctionReturnType(IterationTypeKind.Yield, returnType, !!(flags & FunctionFlags.Async)); + return !!yieldType && isGenericType(yieldType); + case WideningKind.GeneratorNext: + const nextType = getIterationTypeOfGeneratorFunctionReturnType(IterationTypeKind.Next, returnType, !!(flags & FunctionFlags.Async)); + return !!nextType && isGenericType(nextType); + } + return false; + } + function reportErrorsFromWidening(declaration: Declaration, type: Type, wideningKind?: WideningKind) { addLazyDiagnostic(() => { - if (noImplicitAny && getObjectFlags(type) & ObjectFlags.ContainsWideningType && (!wideningKind || !getContextualSignatureForFunctionLikeDeclaration(declaration as FunctionLikeDeclaration))) { - // Report implicit any error within type if possible, otherwise report error on declaration - if (!reportWideningErrorsInType(type)) { - reportImplicitAny(declaration, type, wideningKind); + if (noImplicitAny && getObjectFlags(type) & ObjectFlags.ContainsWideningType) { + if (!wideningKind || isFunctionLikeDeclaration(declaration) && shouldReportErrorsFromWideningWithContextualSignature(declaration, wideningKind)) { + // Report implicit any error within type if possible, otherwise report error on declaration + if (!reportWideningErrorsInType(type)) { + reportImplicitAny(declaration, type, wideningKind); + } } } }); diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 36213fbc314e8..43f4a3eac49f4 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -6626,7 +6626,7 @@ "category": "Error", "code": 7024 }, - "Generator implicitly has yield type '{0}' because it does not yield any values. Consider supplying a return type annotation.": { + "Generator implicitly has yield type '{0}'. Consider supplying a return type annotation.": { "category": "Error", "code": 7025 }, diff --git a/tests/baselines/reference/generatorReturnTypeInferenceNonStrict.errors.txt b/tests/baselines/reference/generatorReturnTypeInferenceNonStrict.errors.txt index 6367bd3d18754..9b69d36b6ed24 100644 --- a/tests/baselines/reference/generatorReturnTypeInferenceNonStrict.errors.txt +++ b/tests/baselines/reference/generatorReturnTypeInferenceNonStrict.errors.txt @@ -4,7 +4,7 @@ generatorReturnTypeInferenceNonStrict.ts(74,15): error TS7057: 'yield' expressio generatorReturnTypeInferenceNonStrict.ts(79,11): error TS7055: 'g301', which lacks return-type annotation, implicitly has an 'any' yield type. generatorReturnTypeInferenceNonStrict.ts(89,11): error TS7055: 'g303', which lacks return-type annotation, implicitly has an 'any' yield type. generatorReturnTypeInferenceNonStrict.ts(126,11): error TS7055: 'g310', which lacks return-type annotation, implicitly has an 'any' yield type. -generatorReturnTypeInferenceNonStrict.ts(131,10): error TS7025: Generator implicitly has yield type 'any' because it does not yield any values. Consider supplying a return type annotation. +generatorReturnTypeInferenceNonStrict.ts(131,10): error TS7025: Generator implicitly has yield type 'any'. Consider supplying a return type annotation. ==== generatorReturnTypeInferenceNonStrict.ts (7 errors) ==== @@ -152,7 +152,7 @@ generatorReturnTypeInferenceNonStrict.ts(131,10): error TS7025: Generator implic function* g311() { // Generator yield* (function*() { ~~~~~~~~ -!!! error TS7025: Generator implicitly has yield type 'any' because it does not yield any values. Consider supplying a return type annotation. +!!! error TS7025: Generator implicitly has yield type 'any'. Consider supplying a return type annotation. const y: string = yield; })(); } diff --git a/tests/baselines/reference/generatorTypeCheck62.errors.txt b/tests/baselines/reference/generatorTypeCheck62.errors.txt index 6599e8fdd0109..0086af9d41938 100644 --- a/tests/baselines/reference/generatorTypeCheck62.errors.txt +++ b/tests/baselines/reference/generatorTypeCheck62.errors.txt @@ -12,9 +12,10 @@ generatorTypeCheck62.ts(32,62): error TS2345: Argument of type '(state: State) = Type 'IteratorReturnResult' is not assignable to type 'IteratorResult'. Type 'IteratorReturnResult' is not assignable to type 'IteratorReturnResult'. Type 'State' is not assignable to type 'void'. +generatorTypeCheck62.ts(32,62): error TS7025: Generator implicitly has yield type 'any'. Consider supplying a return type annotation. -==== generatorTypeCheck62.ts (2 errors) ==== +==== generatorTypeCheck62.ts (3 errors) ==== export interface StrategicState { lastStrategyApplied?: string; } @@ -63,6 +64,8 @@ generatorTypeCheck62.ts(32,62): error TS2345: Argument of type '(state: State) = !!! error TS2345: Type 'IteratorReturnResult' is not assignable to type 'IteratorResult'. !!! error TS2345: Type 'IteratorReturnResult' is not assignable to type 'IteratorReturnResult'. !!! error TS2345: Type 'State' is not assignable to type 'void'. + ~~~~~~~~ +!!! error TS7025: Generator implicitly has yield type 'any'. Consider supplying a return type annotation. yield ; return state; // `return`/`TReturn` isn't supported by `strategy`, so this should error. }); diff --git a/tests/baselines/reference/implicitAnyGenericTypeInference.errors.txt b/tests/baselines/reference/implicitAnyGenericTypeInference.errors.txt new file mode 100644 index 0000000000000..cf72d48df180c --- /dev/null +++ b/tests/baselines/reference/implicitAnyGenericTypeInference.errors.txt @@ -0,0 +1,56 @@ +implicitAnyGenericTypeInference.ts(10,4): error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. +implicitAnyGenericTypeInference.ts(13,4): error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. +implicitAnyGenericTypeInference.ts(16,4): error TS7025: Generator implicitly has yield type 'any'. Consider supplying a return type annotation. +implicitAnyGenericTypeInference.ts(19,4): error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. +implicitAnyGenericTypeInference.ts(22,4): error TS7025: Generator implicitly has yield type 'any'. Consider supplying a return type annotation. +implicitAnyGenericTypeInference.ts(25,4): error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. +implicitAnyGenericTypeInference.ts(28,25): error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. +implicitAnyGenericTypeInference.ts(29,24): error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. + + +==== implicitAnyGenericTypeInference.ts (8 errors) ==== + interface Comparer { + compareTo(x: T, y: U): U; + } + + var c: Comparer; + c = { compareTo: (x, y) => { return y; } }; + var r = c.compareTo(1, ''); + + declare function f1(cb: () => T): void; + f1(() => null); + ~~~~~~~~~~ +!!! error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. + + declare function f2(cb: () => PromiseLike): void; + f2(async () => null); + ~~~~~~~~~~~~~~~~ +!!! error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. + + declare function f3(cb: () => Generator): void; + f3(function* () { yield null; }); + ~~~~~~~~ +!!! error TS7025: Generator implicitly has yield type 'any'. Consider supplying a return type annotation. + + declare function f4(cb: () => Generator): void; + f4(function* () { return null; }); + ~~~~~~~~ +!!! error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. + + declare function f5(cb: () => AsyncGenerator): void; + f5(async function* () { yield null; }); + ~~~~~ +!!! error TS7025: Generator implicitly has yield type 'any'. Consider supplying a return type annotation. + + declare function f6(cb: () => AsyncGenerator): void; + f6(async function* () { return null; }); + ~~~~~ +!!! error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. + + // https://github.com/microsoft/TypeScript/issues/44913 + Promise.resolve().catch(e => null); + ~~~~~~~~~ +!!! error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. + Promise.resolve().then(v => null); + ~~~~~~~~~ +!!! error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. \ No newline at end of file diff --git a/tests/baselines/reference/implicitAnyGenericTypeInference.js b/tests/baselines/reference/implicitAnyGenericTypeInference.js index 0f683cef999a7..951e90552243c 100644 --- a/tests/baselines/reference/implicitAnyGenericTypeInference.js +++ b/tests/baselines/reference/implicitAnyGenericTypeInference.js @@ -7,9 +7,40 @@ interface Comparer { var c: Comparer; c = { compareTo: (x, y) => { return y; } }; -var r = c.compareTo(1, ''); +var r = c.compareTo(1, ''); + +declare function f1(cb: () => T): void; +f1(() => null); + +declare function f2(cb: () => PromiseLike): void; +f2(async () => null); + +declare function f3(cb: () => Generator): void; +f3(function* () { yield null; }); + +declare function f4(cb: () => Generator): void; +f4(function* () { return null; }); + +declare function f5(cb: () => AsyncGenerator): void; +f5(async function* () { yield null; }); + +declare function f6(cb: () => AsyncGenerator): void; +f6(async function* () { return null; }); + +// https://github.com/microsoft/TypeScript/issues/44913 +Promise.resolve().catch(e => null); +Promise.resolve().then(v => null); //// [implicitAnyGenericTypeInference.js] var c; -c = { compareTo: function (x, y) { return y; } }; +c = { compareTo: (x, y) => { return y; } }; var r = c.compareTo(1, ''); +f1(() => null); +f2(async () => null); +f3(function* () { yield null; }); +f4(function* () { return null; }); +f5(async function* () { yield null; }); +f6(async function* () { return null; }); +// https://github.com/microsoft/TypeScript/issues/44913 +Promise.resolve().catch(e => null); +Promise.resolve().then(v => null); diff --git a/tests/baselines/reference/implicitAnyGenericTypeInference.symbols b/tests/baselines/reference/implicitAnyGenericTypeInference.symbols index 7b2eaa1eb3332..d6579b6fd01aa 100644 --- a/tests/baselines/reference/implicitAnyGenericTypeInference.symbols +++ b/tests/baselines/reference/implicitAnyGenericTypeInference.symbols @@ -32,3 +32,79 @@ var r = c.compareTo(1, ''); >c : Symbol(c, Decl(implicitAnyGenericTypeInference.ts, 4, 3)) >compareTo : Symbol(Comparer.compareTo, Decl(implicitAnyGenericTypeInference.ts, 0, 23)) +declare function f1(cb: () => T): void; +>f1 : Symbol(f1, Decl(implicitAnyGenericTypeInference.ts, 6, 27)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 8, 20)) +>cb : Symbol(cb, Decl(implicitAnyGenericTypeInference.ts, 8, 23)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 8, 20)) + +f1(() => null); +>f1 : Symbol(f1, Decl(implicitAnyGenericTypeInference.ts, 6, 27)) + +declare function f2(cb: () => PromiseLike): void; +>f2 : Symbol(f2, Decl(implicitAnyGenericTypeInference.ts, 9, 15)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 11, 20)) +>cb : Symbol(cb, Decl(implicitAnyGenericTypeInference.ts, 11, 23)) +>PromiseLike : Symbol(PromiseLike, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 11, 20)) + +f2(async () => null); +>f2 : Symbol(f2, Decl(implicitAnyGenericTypeInference.ts, 9, 15)) + +declare function f3(cb: () => Generator): void; +>f3 : Symbol(f3, Decl(implicitAnyGenericTypeInference.ts, 12, 21)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 14, 20)) +>cb : Symbol(cb, Decl(implicitAnyGenericTypeInference.ts, 14, 23)) +>Generator : Symbol(Generator, Decl(lib.es2015.generator.d.ts, --, --)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 14, 20)) + +f3(function* () { yield null; }); +>f3 : Symbol(f3, Decl(implicitAnyGenericTypeInference.ts, 12, 21)) + +declare function f4(cb: () => Generator): void; +>f4 : Symbol(f4, Decl(implicitAnyGenericTypeInference.ts, 15, 33)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 17, 20)) +>cb : Symbol(cb, Decl(implicitAnyGenericTypeInference.ts, 17, 23)) +>Generator : Symbol(Generator, Decl(lib.es2015.generator.d.ts, --, --)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 17, 20)) + +f4(function* () { return null; }); +>f4 : Symbol(f4, Decl(implicitAnyGenericTypeInference.ts, 15, 33)) + +declare function f5(cb: () => AsyncGenerator): void; +>f5 : Symbol(f5, Decl(implicitAnyGenericTypeInference.ts, 18, 34)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 20, 20)) +>cb : Symbol(cb, Decl(implicitAnyGenericTypeInference.ts, 20, 23)) +>AsyncGenerator : Symbol(AsyncGenerator, Decl(lib.es2018.asyncgenerator.d.ts, --, --)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 20, 20)) + +f5(async function* () { yield null; }); +>f5 : Symbol(f5, Decl(implicitAnyGenericTypeInference.ts, 18, 34)) + +declare function f6(cb: () => AsyncGenerator): void; +>f6 : Symbol(f6, Decl(implicitAnyGenericTypeInference.ts, 21, 39)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 23, 20)) +>cb : Symbol(cb, Decl(implicitAnyGenericTypeInference.ts, 23, 23)) +>AsyncGenerator : Symbol(AsyncGenerator, Decl(lib.es2018.asyncgenerator.d.ts, --, --)) +>T : Symbol(T, Decl(implicitAnyGenericTypeInference.ts, 23, 20)) + +f6(async function* () { return null; }); +>f6 : Symbol(f6, Decl(implicitAnyGenericTypeInference.ts, 21, 39)) + +// https://github.com/microsoft/TypeScript/issues/44913 +Promise.resolve().catch(e => null); +>Promise.resolve().catch : Symbol(Promise.catch, Decl(lib.es5.d.ts, --, --)) +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>catch : Symbol(Promise.catch, Decl(lib.es5.d.ts, --, --)) +>e : Symbol(e, Decl(implicitAnyGenericTypeInference.ts, 27, 24)) + +Promise.resolve().then(v => null); +>Promise.resolve().then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>v : Symbol(v, Decl(implicitAnyGenericTypeInference.ts, 28, 23)) + diff --git a/tests/baselines/reference/implicitAnyGenericTypeInference.types b/tests/baselines/reference/implicitAnyGenericTypeInference.types index f297981afc45e..61c257b6f9858 100644 --- a/tests/baselines/reference/implicitAnyGenericTypeInference.types +++ b/tests/baselines/reference/implicitAnyGenericTypeInference.types @@ -1,5 +1,9 @@ //// [tests/cases/compiler/implicitAnyGenericTypeInference.ts] //// +=== Performance Stats === +Type Count: 1,000 +Instantiation count: 2,500 + === implicitAnyGenericTypeInference.ts === interface Comparer { compareTo(x: T, y: U): U; @@ -27,6 +31,7 @@ c = { compareTo: (x, y) => { return y; } }; >(x, y) => { return y; } : (x: any, y: U) => U > : ^ ^^ ^^^^^^^ ^^^^^^^^^ >x : any +> : ^^^ >y : U > : ^ >y : U @@ -48,3 +53,132 @@ var r = c.compareTo(1, ''); >'' : "" > : ^^ +declare function f1(cb: () => T): void; +>f1 : (cb: () => T) => void +> : ^ ^^ ^^ ^^^^^ +>cb : () => T +> : ^^^^^^ + +f1(() => null); +>f1(() => null) : void +> : ^^^^ +>f1 : (cb: () => T) => void +> : ^ ^^ ^^ ^^^^^ +>() => null : () => any +> : ^^^^^^^^^ + +declare function f2(cb: () => PromiseLike): void; +>f2 : (cb: () => PromiseLike) => void +> : ^ ^^ ^^ ^^^^^ +>cb : () => PromiseLike +> : ^^^^^^ + +f2(async () => null); +>f2(async () => null) : void +> : ^^^^ +>f2 : (cb: () => PromiseLike) => void +> : ^ ^^ ^^ ^^^^^ +>async () => null : () => Promise +> : ^^^^^^^^^^^^^^^^^^ + +declare function f3(cb: () => Generator): void; +>f3 : (cb: () => Generator) => void +> : ^ ^^ ^^ ^^^^^ +>cb : () => Generator +> : ^^^^^^ + +f3(function* () { yield null; }); +>f3(function* () { yield null; }) : void +> : ^^^^ +>f3 : (cb: () => Generator) => void +> : ^ ^^ ^^ ^^^^^ +>function* () { yield null; } : () => Generator +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>yield null : any +> : ^^^ + +declare function f4(cb: () => Generator): void; +>f4 : (cb: () => Generator) => void +> : ^ ^^ ^^ ^^^^^ +>cb : () => Generator +> : ^^^^^^ + +f4(function* () { return null; }); +>f4(function* () { return null; }) : void +> : ^^^^ +>f4 : (cb: () => Generator) => void +> : ^ ^^ ^^ ^^^^^ +>function* () { return null; } : () => Generator +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +declare function f5(cb: () => AsyncGenerator): void; +>f5 : (cb: () => AsyncGenerator) => void +> : ^ ^^ ^^ ^^^^^ +>cb : () => AsyncGenerator +> : ^^^^^^ + +f5(async function* () { yield null; }); +>f5(async function* () { yield null; }) : void +> : ^^^^ +>f5 : (cb: () => AsyncGenerator) => void +> : ^ ^^ ^^ ^^^^^ +>async function* () { yield null; } : () => AsyncGenerator +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>yield null : any +> : ^^^ + +declare function f6(cb: () => AsyncGenerator): void; +>f6 : (cb: () => AsyncGenerator) => void +> : ^ ^^ ^^ ^^^^^ +>cb : () => AsyncGenerator +> : ^^^^^^ + +f6(async function* () { return null; }); +>f6(async function* () { return null; }) : void +> : ^^^^ +>f6 : (cb: () => AsyncGenerator) => void +> : ^ ^^ ^^ ^^^^^ +>async function* () { return null; } : () => AsyncGenerator +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +// https://github.com/microsoft/TypeScript/issues/44913 +Promise.resolve().catch(e => null); +>Promise.resolve().catch(e => null) : Promise +> : ^^^^^^^^^^^^ +>Promise.resolve().catch : (onrejected?: (reason: any) => TResult | PromiseLike) => Promise +> : ^ ^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>Promise.resolve() : Promise +> : ^^^^^^^^^^^^^ +>Promise.resolve : { (): Promise; (value: T): Promise>; (value: T | PromiseLike): Promise>; } +> : ^^^^^^ ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^ ^^^ ^^^ +>Promise : PromiseConstructor +> : ^^^^^^^^^^^^^^^^^^ +>resolve : { (): Promise; (value: T): Promise>; (value: T | PromiseLike): Promise>; } +> : ^^^^^^ ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^ ^^^ ^^^ +>catch : (onrejected?: (reason: any) => TResult | PromiseLike) => Promise +> : ^ ^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>e => null : (e: any) => any +> : ^ ^^^^^^^^^^^^^ +>e : any +> : ^^^ + +Promise.resolve().then(v => null); +>Promise.resolve().then(v => null) : Promise +> : ^^^^^^^^^^^^ +>Promise.resolve().then : (onfulfilled?: (value: void) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +> : ^ ^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>Promise.resolve() : Promise +> : ^^^^^^^^^^^^^ +>Promise.resolve : { (): Promise; (value: T): Promise>; (value: T | PromiseLike): Promise>; } +> : ^^^^^^ ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^ ^^^ ^^^ +>Promise : PromiseConstructor +> : ^^^^^^^^^^^^^^^^^^ +>resolve : { (): Promise; (value: T): Promise>; (value: T | PromiseLike): Promise>; } +> : ^^^^^^ ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^ ^^^ ^^^ +>then : (onfulfilled?: (value: void) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +> : ^ ^^^^^^^^^ ^^^^^^^^^^ ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>v => null : (v: void) => any +> : ^ ^^^^^^^^^^^^^^ +>v : void +> : ^^^^ + diff --git a/tests/cases/compiler/implicitAnyGenericTypeInference.ts b/tests/cases/compiler/implicitAnyGenericTypeInference.ts index 7199287a96f09..55f999742b2e8 100644 --- a/tests/cases/compiler/implicitAnyGenericTypeInference.ts +++ b/tests/cases/compiler/implicitAnyGenericTypeInference.ts @@ -1,4 +1,5 @@ // @noimplicitany: true +// @target: esnext interface Comparer { compareTo(x: T, y: U): U; @@ -6,4 +7,26 @@ interface Comparer { var c: Comparer; c = { compareTo: (x, y) => { return y; } }; -var r = c.compareTo(1, ''); \ No newline at end of file +var r = c.compareTo(1, ''); + +declare function f1(cb: () => T): void; +f1(() => null); + +declare function f2(cb: () => PromiseLike): void; +f2(async () => null); + +declare function f3(cb: () => Generator): void; +f3(function* () { yield null; }); + +declare function f4(cb: () => Generator): void; +f4(function* () { return null; }); + +declare function f5(cb: () => AsyncGenerator): void; +f5(async function* () { yield null; }); + +declare function f6(cb: () => AsyncGenerator): void; +f6(async function* () { return null; }); + +// https://github.com/microsoft/TypeScript/issues/44913 +Promise.resolve().catch(e => null); +Promise.resolve().then(v => null); \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy