mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
support contextual return type of iife (#45007)
This commit is contained in:
@@ -25352,6 +25352,10 @@ namespace ts {
|
||||
if (signature && !isResolvingReturnTypeOfSignature(signature)) {
|
||||
return getReturnTypeOfSignature(signature);
|
||||
}
|
||||
const iife = getImmediatelyInvokedFunctionExpression(functionDecl);
|
||||
if (iife) {
|
||||
return getContextualType(iife);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
//// [contextualReturnTypeOfIIFE.ts]
|
||||
const test1: Promise<[one: number, two: string]> = (async () => {
|
||||
return [1, 'two'];
|
||||
})();
|
||||
|
||||
const test2: Promise<[one: number, two: string]> = new Promise(
|
||||
(resolve) => resolve([1, 'two']),
|
||||
);
|
||||
|
||||
const obj: { foo: [one: number, two: string] } = {
|
||||
foo: (() => [1, 'two'])()
|
||||
};
|
||||
|
||||
|
||||
//// [contextualReturnTypeOfIIFE.js]
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var _this = this;
|
||||
var test1 = (function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
return __generator(this, function (_a) {
|
||||
return [2 /*return*/, [1, 'two']];
|
||||
});
|
||||
}); })();
|
||||
var test2 = new Promise(function (resolve) { return resolve([1, 'two']); });
|
||||
var obj = {
|
||||
foo: (function () { return [1, 'two']; })()
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
=== tests/cases/compiler/contextualReturnTypeOfIIFE.ts ===
|
||||
const test1: Promise<[one: number, two: string]> = (async () => {
|
||||
>test1 : Symbol(test1, Decl(contextualReturnTypeOfIIFE.ts, 0, 5))
|
||||
>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, --, --))
|
||||
|
||||
return [1, 'two'];
|
||||
})();
|
||||
|
||||
const test2: Promise<[one: number, two: string]> = new Promise(
|
||||
>test2 : Symbol(test2, Decl(contextualReturnTypeOfIIFE.ts, 4, 5))
|
||||
>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, --, --))
|
||||
>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) => resolve([1, 'two']),
|
||||
>resolve : Symbol(resolve, Decl(contextualReturnTypeOfIIFE.ts, 5, 5))
|
||||
>resolve : Symbol(resolve, Decl(contextualReturnTypeOfIIFE.ts, 5, 5))
|
||||
|
||||
);
|
||||
|
||||
const obj: { foo: [one: number, two: string] } = {
|
||||
>obj : Symbol(obj, Decl(contextualReturnTypeOfIIFE.ts, 8, 5))
|
||||
>foo : Symbol(foo, Decl(contextualReturnTypeOfIIFE.ts, 8, 12))
|
||||
|
||||
foo: (() => [1, 'two'])()
|
||||
>foo : Symbol(foo, Decl(contextualReturnTypeOfIIFE.ts, 8, 50))
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
=== tests/cases/compiler/contextualReturnTypeOfIIFE.ts ===
|
||||
const test1: Promise<[one: number, two: string]> = (async () => {
|
||||
>test1 : Promise<[one: number, two: string]>
|
||||
>(async () => { return [1, 'two'];})() : Promise<[number, string]>
|
||||
>(async () => { return [1, 'two'];}) : () => Promise<[number, string]>
|
||||
>async () => { return [1, 'two'];} : () => Promise<[number, string]>
|
||||
|
||||
return [1, 'two'];
|
||||
>[1, 'two'] : [number, string]
|
||||
>1 : 1
|
||||
>'two' : "two"
|
||||
|
||||
})();
|
||||
|
||||
const test2: Promise<[one: number, two: string]> = new Promise(
|
||||
>test2 : Promise<[one: number, two: string]>
|
||||
>new Promise( (resolve) => resolve([1, 'two']),) : Promise<[one: number, two: string]>
|
||||
>Promise : PromiseConstructor
|
||||
|
||||
(resolve) => resolve([1, 'two']),
|
||||
>(resolve) => resolve([1, 'two']) : (resolve: (value: [one: number, two: string] | PromiseLike<[one: number, two: string]>) => void) => void
|
||||
>resolve : (value: [one: number, two: string] | PromiseLike<[one: number, two: string]>) => void
|
||||
>resolve([1, 'two']) : void
|
||||
>resolve : (value: [one: number, two: string] | PromiseLike<[one: number, two: string]>) => void
|
||||
>[1, 'two'] : [number, string]
|
||||
>1 : 1
|
||||
>'two' : "two"
|
||||
|
||||
);
|
||||
|
||||
const obj: { foo: [one: number, two: string] } = {
|
||||
>obj : { foo: [one: number, two: string]; }
|
||||
>foo : [one: number, two: string]
|
||||
>{ foo: (() => [1, 'two'])()} : { foo: [number, string]; }
|
||||
|
||||
foo: (() => [1, 'two'])()
|
||||
>foo : [number, string]
|
||||
>(() => [1, 'two'])() : [number, string]
|
||||
>(() => [1, 'two']) : () => [number, string]
|
||||
>() => [1, 'two'] : () => [number, string]
|
||||
>[1, 'two'] : [number, string]
|
||||
>1 : 1
|
||||
>'two' : "two"
|
||||
|
||||
};
|
||||
|
||||
@@ -7,7 +7,9 @@ function* g(): IterableIterator<(x: string) => number> {
|
||||
yield * function* () {
|
||||
yield x => x.length;
|
||||
>x : Symbol(x, Decl(generatorTypeCheck27.ts, 2, 13))
|
||||
>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(generatorTypeCheck27.ts, 2, 13))
|
||||
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
} ();
|
||||
}
|
||||
|
||||
@@ -5,16 +5,16 @@ function* g(): IterableIterator<(x: string) => number> {
|
||||
|
||||
yield * function* () {
|
||||
>yield * function* () { yield x => x.length; } () : void
|
||||
>function* () { yield x => x.length; } () : Generator<(x: any) => any, void, unknown>
|
||||
>function* () { yield x => x.length; } : () => Generator<(x: any) => any, void, unknown>
|
||||
>function* () { yield x => x.length; } () : Generator<(x: string) => number, void, undefined>
|
||||
>function* () { yield x => x.length; } : () => Generator<(x: string) => number, void, undefined>
|
||||
|
||||
yield x => x.length;
|
||||
>yield x => x.length : any
|
||||
>x => x.length : (x: any) => any
|
||||
>x : any
|
||||
>x.length : any
|
||||
>x : any
|
||||
>length : any
|
||||
>yield x => x.length : undefined
|
||||
>x => x.length : (x: string) => number
|
||||
>x : string
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
|
||||
} ();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ function* g2(): Iterator<Iterable<(x: string) => number>> {
|
||||
yield function* () {
|
||||
yield x => x.length;
|
||||
>x : Symbol(x, Decl(generatorTypeCheck29.ts, 2, 13))
|
||||
>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(generatorTypeCheck29.ts, 2, 13))
|
||||
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
} ()
|
||||
}
|
||||
|
||||
@@ -5,16 +5,16 @@ function* g2(): Iterator<Iterable<(x: string) => number>> {
|
||||
|
||||
yield function* () {
|
||||
>yield function* () { yield x => x.length; } () : undefined
|
||||
>function* () { yield x => x.length; } () : Generator<(x: any) => any, void, unknown>
|
||||
>function* () { yield x => x.length; } : () => Generator<(x: any) => any, void, unknown>
|
||||
>function* () { yield x => x.length; } () : Generator<(x: string) => number, void, undefined>
|
||||
>function* () { yield x => x.length; } : () => Generator<(x: string) => number, void, undefined>
|
||||
|
||||
yield x => x.length;
|
||||
>yield x => x.length : any
|
||||
>x => x.length : (x: any) => any
|
||||
>x : any
|
||||
>x.length : any
|
||||
>x : any
|
||||
>length : any
|
||||
>yield x => x.length : undefined
|
||||
>x => x.length : (x: string) => number
|
||||
>x : string
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
|
||||
} ()
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ function* g2(): Iterator<Iterable<(x: string) => number>> {
|
||||
yield function* () {
|
||||
yield x => x.length;
|
||||
>x : Symbol(x, Decl(generatorTypeCheck30.ts, 2, 13))
|
||||
>x.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(generatorTypeCheck30.ts, 2, 13))
|
||||
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --))
|
||||
|
||||
} ()
|
||||
}
|
||||
|
||||
@@ -5,16 +5,16 @@ function* g2(): Iterator<Iterable<(x: string) => number>> {
|
||||
|
||||
yield function* () {
|
||||
>yield function* () { yield x => x.length; } () : undefined
|
||||
>function* () { yield x => x.length; } () : Generator<(x: any) => any, void, unknown>
|
||||
>function* () { yield x => x.length; } : () => Generator<(x: any) => any, void, unknown>
|
||||
>function* () { yield x => x.length; } () : Generator<(x: string) => number, void, undefined>
|
||||
>function* () { yield x => x.length; } : () => Generator<(x: string) => number, void, undefined>
|
||||
|
||||
yield x => x.length;
|
||||
>yield x => x.length : any
|
||||
>x => x.length : (x: any) => any
|
||||
>x : any
|
||||
>x.length : any
|
||||
>x : any
|
||||
>length : any
|
||||
>yield x => x.length : undefined
|
||||
>x => x.length : (x: string) => number
|
||||
>x : string
|
||||
>x.length : number
|
||||
>x : string
|
||||
>length : number
|
||||
|
||||
} ()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts(2,11): error TS2322: Type 'Generator<(x: any) => any, void, unknown>' is not assignable to type '() => Iterable<(x: string) => number>'.
|
||||
Type 'Generator<(x: any) => any, void, unknown>' provides no match for the signature '(): Iterable<(x: string) => number>'.
|
||||
tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts(2,11): error TS2322: Type 'Generator<(x: any) => any, void, any>' is not assignable to type '() => Iterable<(x: string) => number>'.
|
||||
Type 'Generator<(x: any) => any, void, any>' provides no match for the signature '(): Iterable<(x: string) => number>'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts (1 errors) ====
|
||||
@@ -10,6 +10,6 @@ tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts(2,11): erro
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
} ()
|
||||
~~~~~~~~
|
||||
!!! error TS2322: Type 'Generator<(x: any) => any, void, unknown>' is not assignable to type '() => Iterable<(x: string) => number>'.
|
||||
!!! error TS2322: Type 'Generator<(x: any) => any, void, unknown>' provides no match for the signature '(): Iterable<(x: string) => number>'.
|
||||
!!! error TS2322: Type 'Generator<(x: any) => any, void, any>' is not assignable to type '() => Iterable<(x: string) => number>'.
|
||||
!!! error TS2322: Type 'Generator<(x: any) => any, void, any>' provides no match for the signature '(): Iterable<(x: string) => number>'.
|
||||
}
|
||||
@@ -5,8 +5,8 @@ function* g2(): Iterator<() => Iterable<(x: string) => number>> {
|
||||
|
||||
yield function* () {
|
||||
>yield function* () { yield x => x.length; } () : undefined
|
||||
>function* () { yield x => x.length; } () : Generator<(x: any) => any, void, unknown>
|
||||
>function* () { yield x => x.length; } : () => Generator<(x: any) => any, void, unknown>
|
||||
>function* () { yield x => x.length; } () : Generator<(x: any) => any, void, any>
|
||||
>function* () { yield x => x.length; } : () => Generator<(x: any) => any, void, any>
|
||||
|
||||
yield x => x.length;
|
||||
>yield x => x.length : any
|
||||
|
||||
@@ -122,14 +122,14 @@ const assignability4: () => AsyncIterableIterator<number> = async function * ()
|
||||
};
|
||||
const assignability5: () => AsyncIterableIterator<number> = async function * () {
|
||||
>assignability5 : () => AsyncIterableIterator<number>
|
||||
>async function * () { yield* (async function * () { yield 1; })();} : () => AsyncGenerator<number, void, unknown>
|
||||
>async function * () { yield* (async function * () { yield 1; })();} : () => AsyncGenerator<number, void, undefined>
|
||||
|
||||
yield* (async function * () { yield 1; })();
|
||||
>yield* (async function * () { yield 1; })() : void
|
||||
>(async function * () { yield 1; })() : AsyncGenerator<number, void, unknown>
|
||||
>(async function * () { yield 1; }) : () => AsyncGenerator<number, void, unknown>
|
||||
>async function * () { yield 1; } : () => AsyncGenerator<number, void, unknown>
|
||||
>yield 1 : any
|
||||
>(async function * () { yield 1; })() : AsyncGenerator<number, void, undefined>
|
||||
>(async function * () { yield 1; }) : () => AsyncGenerator<number, void, undefined>
|
||||
>async function * () { yield 1; } : () => AsyncGenerator<number, void, undefined>
|
||||
>yield 1 : undefined
|
||||
>1 : 1
|
||||
|
||||
};
|
||||
@@ -182,14 +182,14 @@ const assignability9: () => AsyncIterable<number> = async function * () {
|
||||
};
|
||||
const assignability10: () => AsyncIterable<number> = async function * () {
|
||||
>assignability10 : () => AsyncIterable<number>
|
||||
>async function * () { yield* (async function * () { yield 1; })();} : () => AsyncGenerator<number, void, unknown>
|
||||
>async function * () { yield* (async function * () { yield 1; })();} : () => AsyncGenerator<number, void, undefined>
|
||||
|
||||
yield* (async function * () { yield 1; })();
|
||||
>yield* (async function * () { yield 1; })() : void
|
||||
>(async function * () { yield 1; })() : AsyncGenerator<number, void, unknown>
|
||||
>(async function * () { yield 1; }) : () => AsyncGenerator<number, void, unknown>
|
||||
>async function * () { yield 1; } : () => AsyncGenerator<number, void, unknown>
|
||||
>yield 1 : any
|
||||
>(async function * () { yield 1; })() : AsyncGenerator<number, void, undefined>
|
||||
>(async function * () { yield 1; }) : () => AsyncGenerator<number, void, undefined>
|
||||
>async function * () { yield 1; } : () => AsyncGenerator<number, void, undefined>
|
||||
>yield 1 : undefined
|
||||
>1 : 1
|
||||
|
||||
};
|
||||
@@ -242,14 +242,14 @@ const assignability14: () => AsyncIterator<number> = async function * () {
|
||||
};
|
||||
const assignability15: () => AsyncIterator<number> = async function * () {
|
||||
>assignability15 : () => AsyncIterator<number>
|
||||
>async function * () { yield* (async function * () { yield 1; })();} : () => AsyncGenerator<number, void, unknown>
|
||||
>async function * () { yield* (async function * () { yield 1; })();} : () => AsyncGenerator<number, void, undefined>
|
||||
|
||||
yield* (async function * () { yield 1; })();
|
||||
>yield* (async function * () { yield 1; })() : void
|
||||
>(async function * () { yield 1; })() : AsyncGenerator<number, void, unknown>
|
||||
>(async function * () { yield 1; }) : () => AsyncGenerator<number, void, unknown>
|
||||
>async function * () { yield 1; } : () => AsyncGenerator<number, void, unknown>
|
||||
>yield 1 : any
|
||||
>(async function * () { yield 1; })() : AsyncGenerator<number, void, undefined>
|
||||
>(async function * () { yield 1; }) : () => AsyncGenerator<number, void, undefined>
|
||||
>async function * () { yield 1; } : () => AsyncGenerator<number, void, undefined>
|
||||
>yield 1 : undefined
|
||||
>1 : 1
|
||||
|
||||
};
|
||||
@@ -297,10 +297,10 @@ async function * explicitReturnType5(): AsyncIterableIterator<number> {
|
||||
|
||||
yield* (async function * () { yield 1; })();
|
||||
>yield* (async function * () { yield 1; })() : void
|
||||
>(async function * () { yield 1; })() : AsyncGenerator<number, void, unknown>
|
||||
>(async function * () { yield 1; }) : () => AsyncGenerator<number, void, unknown>
|
||||
>async function * () { yield 1; } : () => AsyncGenerator<number, void, unknown>
|
||||
>yield 1 : any
|
||||
>(async function * () { yield 1; })() : AsyncGenerator<number, void, undefined>
|
||||
>(async function * () { yield 1; }) : () => AsyncGenerator<number, void, undefined>
|
||||
>async function * () { yield 1; } : () => AsyncGenerator<number, void, undefined>
|
||||
>yield 1 : undefined
|
||||
>1 : 1
|
||||
}
|
||||
async function * explicitReturnType6(): AsyncIterable<number> {
|
||||
@@ -347,10 +347,10 @@ async function * explicitReturnType10(): AsyncIterable<number> {
|
||||
|
||||
yield* (async function * () { yield 1; })();
|
||||
>yield* (async function * () { yield 1; })() : void
|
||||
>(async function * () { yield 1; })() : AsyncGenerator<number, void, unknown>
|
||||
>(async function * () { yield 1; }) : () => AsyncGenerator<number, void, unknown>
|
||||
>async function * () { yield 1; } : () => AsyncGenerator<number, void, unknown>
|
||||
>yield 1 : any
|
||||
>(async function * () { yield 1; })() : AsyncGenerator<number, void, undefined>
|
||||
>(async function * () { yield 1; }) : () => AsyncGenerator<number, void, undefined>
|
||||
>async function * () { yield 1; } : () => AsyncGenerator<number, void, undefined>
|
||||
>yield 1 : undefined
|
||||
>1 : 1
|
||||
}
|
||||
async function * explicitReturnType11(): AsyncIterator<number> {
|
||||
@@ -397,10 +397,10 @@ async function * explicitReturnType15(): AsyncIterator<number> {
|
||||
|
||||
yield* (async function * () { yield 1; })();
|
||||
>yield* (async function * () { yield 1; })() : void
|
||||
>(async function * () { yield 1; })() : AsyncGenerator<number, void, unknown>
|
||||
>(async function * () { yield 1; }) : () => AsyncGenerator<number, void, unknown>
|
||||
>async function * () { yield 1; } : () => AsyncGenerator<number, void, unknown>
|
||||
>yield 1 : any
|
||||
>(async function * () { yield 1; })() : AsyncGenerator<number, void, undefined>
|
||||
>(async function * () { yield 1; }) : () => AsyncGenerator<number, void, undefined>
|
||||
>async function * () { yield 1; } : () => AsyncGenerator<number, void, undefined>
|
||||
>yield 1 : undefined
|
||||
>1 : 1
|
||||
}
|
||||
async function * explicitReturnType16(): {} {
|
||||
|
||||
@@ -10,26 +10,22 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(13,7): error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterableIterator<number>'.
|
||||
Type 'AsyncGenerator<string, void, undefined>' is not assignable to type 'AsyncIterableIterator<number>'.
|
||||
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(16,7): error TS2322: Type '() => AsyncGenerator<string, void, unknown>' is not assignable to type '() => AsyncIterableIterator<number>'.
|
||||
Call signature return types 'AsyncGenerator<string, void, unknown>' and 'AsyncIterableIterator<number>' are incompatible.
|
||||
The types returned by 'next(...)' are incompatible between these types.
|
||||
Type 'Promise<IteratorResult<string, void>>' is not assignable to type 'Promise<IteratorResult<number, any>>'.
|
||||
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(16,7): error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterableIterator<number>'.
|
||||
Type 'AsyncGenerator<string, void, undefined>' is not assignable to type 'AsyncIterableIterator<number>'.
|
||||
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(19,7): error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterable<number>'.
|
||||
Call signature return types 'AsyncGenerator<string, void, undefined>' and 'AsyncIterable<number>' are incompatible.
|
||||
The types of '[Symbol.asyncIterator]().next' are incompatible between these types.
|
||||
Type '(...args: [] | [undefined]) => Promise<IteratorResult<string, void>>' is not assignable to type '(...args: [] | [undefined]) => Promise<IteratorResult<number, any>>'.
|
||||
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(22,7): error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterable<number>'.
|
||||
Type 'AsyncGenerator<string, void, undefined>' is not assignable to type 'AsyncIterable<number>'.
|
||||
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(25,7): error TS2322: Type '() => AsyncGenerator<string, void, unknown>' is not assignable to type '() => AsyncIterable<number>'.
|
||||
Call signature return types 'AsyncGenerator<string, void, unknown>' and 'AsyncIterable<number>' are incompatible.
|
||||
The types of '[Symbol.asyncIterator]().next' are incompatible between these types.
|
||||
Type '(...args: [] | [unknown]) => Promise<IteratorResult<string, void>>' is not assignable to type '(...args: [] | [undefined]) => Promise<IteratorResult<number, any>>'.
|
||||
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(25,7): error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterable<number>'.
|
||||
Type 'AsyncGenerator<string, void, undefined>' is not assignable to type 'AsyncIterable<number>'.
|
||||
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(28,7): error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterator<number, any, undefined>'.
|
||||
Type 'AsyncGenerator<string, void, undefined>' is not assignable to type 'AsyncIterator<number, any, undefined>'.
|
||||
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(31,7): error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterator<number, any, undefined>'.
|
||||
Type 'AsyncGenerator<string, void, undefined>' is not assignable to type 'AsyncIterator<number, any, undefined>'.
|
||||
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(34,7): error TS2322: Type '() => AsyncGenerator<string, void, unknown>' is not assignable to type '() => AsyncIterator<number, any, undefined>'.
|
||||
Type 'AsyncGenerator<string, void, unknown>' is not assignable to type 'AsyncIterator<number, any, undefined>'.
|
||||
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(34,7): error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterator<number, any, undefined>'.
|
||||
Type 'AsyncGenerator<string, void, undefined>' is not assignable to type 'AsyncIterator<number, any, undefined>'.
|
||||
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(38,11): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(41,12): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(44,12): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
@@ -83,10 +79,8 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(
|
||||
};
|
||||
const assignability3: () => AsyncIterableIterator<number> = async function * () {
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '() => AsyncGenerator<string, void, unknown>' is not assignable to type '() => AsyncIterableIterator<number>'.
|
||||
!!! error TS2322: Call signature return types 'AsyncGenerator<string, void, unknown>' and 'AsyncIterableIterator<number>' are incompatible.
|
||||
!!! error TS2322: The types returned by 'next(...)' are incompatible between these types.
|
||||
!!! error TS2322: Type 'Promise<IteratorResult<string, void>>' is not assignable to type 'Promise<IteratorResult<number, any>>'.
|
||||
!!! error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterableIterator<number>'.
|
||||
!!! error TS2322: Type 'AsyncGenerator<string, void, undefined>' is not assignable to type 'AsyncIterableIterator<number>'.
|
||||
yield* (async function * () { yield "a"; })();
|
||||
};
|
||||
const assignability4: () => AsyncIterable<number> = async function * () {
|
||||
@@ -105,10 +99,8 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(
|
||||
};
|
||||
const assignability6: () => AsyncIterable<number> = async function * () {
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '() => AsyncGenerator<string, void, unknown>' is not assignable to type '() => AsyncIterable<number>'.
|
||||
!!! error TS2322: Call signature return types 'AsyncGenerator<string, void, unknown>' and 'AsyncIterable<number>' are incompatible.
|
||||
!!! error TS2322: The types of '[Symbol.asyncIterator]().next' are incompatible between these types.
|
||||
!!! error TS2322: Type '(...args: [] | [unknown]) => Promise<IteratorResult<string, void>>' is not assignable to type '(...args: [] | [undefined]) => Promise<IteratorResult<number, any>>'.
|
||||
!!! error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterable<number>'.
|
||||
!!! error TS2322: Type 'AsyncGenerator<string, void, undefined>' is not assignable to type 'AsyncIterable<number>'.
|
||||
yield* (async function * () { yield "a"; })();
|
||||
};
|
||||
const assignability7: () => AsyncIterator<number> = async function * () {
|
||||
@@ -125,8 +117,8 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(
|
||||
};
|
||||
const assignability9: () => AsyncIterator<number> = async function * () {
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '() => AsyncGenerator<string, void, unknown>' is not assignable to type '() => AsyncIterator<number, any, undefined>'.
|
||||
!!! error TS2322: Type 'AsyncGenerator<string, void, unknown>' is not assignable to type 'AsyncIterator<number, any, undefined>'.
|
||||
!!! error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterator<number, any, undefined>'.
|
||||
!!! error TS2322: Type 'AsyncGenerator<string, void, undefined>' is not assignable to type 'AsyncIterator<number, any, undefined>'.
|
||||
yield* (async function * () { yield "a"; })();
|
||||
};
|
||||
async function * explicitReturnType1(): AsyncIterableIterator<number> {
|
||||
|
||||
@@ -49,14 +49,14 @@ const assignability2: () => AsyncIterableIterator<number> = async function * ()
|
||||
};
|
||||
const assignability3: () => AsyncIterableIterator<number> = async function * () {
|
||||
>assignability3 : () => AsyncIterableIterator<number>
|
||||
>async function * () { yield* (async function * () { yield "a"; })();} : () => AsyncGenerator<string, void, unknown>
|
||||
>async function * () { yield* (async function * () { yield "a"; })();} : () => AsyncGenerator<string, void, undefined>
|
||||
|
||||
yield* (async function * () { yield "a"; })();
|
||||
>yield* (async function * () { yield "a"; })() : void
|
||||
>(async function * () { yield "a"; })() : AsyncGenerator<string, void, unknown>
|
||||
>(async function * () { yield "a"; }) : () => AsyncGenerator<string, void, unknown>
|
||||
>async function * () { yield "a"; } : () => AsyncGenerator<string, void, unknown>
|
||||
>yield "a" : any
|
||||
>(async function * () { yield "a"; })() : AsyncGenerator<string, void, undefined>
|
||||
>(async function * () { yield "a"; }) : () => AsyncGenerator<string, void, undefined>
|
||||
>async function * () { yield "a"; } : () => AsyncGenerator<string, void, undefined>
|
||||
>yield "a" : undefined
|
||||
>"a" : "a"
|
||||
|
||||
};
|
||||
@@ -82,14 +82,14 @@ const assignability5: () => AsyncIterable<number> = async function * () {
|
||||
};
|
||||
const assignability6: () => AsyncIterable<number> = async function * () {
|
||||
>assignability6 : () => AsyncIterable<number>
|
||||
>async function * () { yield* (async function * () { yield "a"; })();} : () => AsyncGenerator<string, void, unknown>
|
||||
>async function * () { yield* (async function * () { yield "a"; })();} : () => AsyncGenerator<string, void, undefined>
|
||||
|
||||
yield* (async function * () { yield "a"; })();
|
||||
>yield* (async function * () { yield "a"; })() : void
|
||||
>(async function * () { yield "a"; })() : AsyncGenerator<string, void, unknown>
|
||||
>(async function * () { yield "a"; }) : () => AsyncGenerator<string, void, unknown>
|
||||
>async function * () { yield "a"; } : () => AsyncGenerator<string, void, unknown>
|
||||
>yield "a" : any
|
||||
>(async function * () { yield "a"; })() : AsyncGenerator<string, void, undefined>
|
||||
>(async function * () { yield "a"; }) : () => AsyncGenerator<string, void, undefined>
|
||||
>async function * () { yield "a"; } : () => AsyncGenerator<string, void, undefined>
|
||||
>yield "a" : undefined
|
||||
>"a" : "a"
|
||||
|
||||
};
|
||||
@@ -115,14 +115,14 @@ const assignability8: () => AsyncIterator<number> = async function * () {
|
||||
};
|
||||
const assignability9: () => AsyncIterator<number> = async function * () {
|
||||
>assignability9 : () => AsyncIterator<number>
|
||||
>async function * () { yield* (async function * () { yield "a"; })();} : () => AsyncGenerator<string, void, unknown>
|
||||
>async function * () { yield* (async function * () { yield "a"; })();} : () => AsyncGenerator<string, void, undefined>
|
||||
|
||||
yield* (async function * () { yield "a"; })();
|
||||
>yield* (async function * () { yield "a"; })() : void
|
||||
>(async function * () { yield "a"; })() : AsyncGenerator<string, void, unknown>
|
||||
>(async function * () { yield "a"; }) : () => AsyncGenerator<string, void, unknown>
|
||||
>async function * () { yield "a"; } : () => AsyncGenerator<string, void, unknown>
|
||||
>yield "a" : any
|
||||
>(async function * () { yield "a"; })() : AsyncGenerator<string, void, undefined>
|
||||
>(async function * () { yield "a"; }) : () => AsyncGenerator<string, void, undefined>
|
||||
>async function * () { yield "a"; } : () => AsyncGenerator<string, void, undefined>
|
||||
>yield "a" : undefined
|
||||
>"a" : "a"
|
||||
|
||||
};
|
||||
@@ -147,10 +147,10 @@ async function * explicitReturnType3(): AsyncIterableIterator<number> {
|
||||
|
||||
yield* (async function * () { yield "a"; })();
|
||||
>yield* (async function * () { yield "a"; })() : void
|
||||
>(async function * () { yield "a"; })() : AsyncGenerator<string, void, unknown>
|
||||
>(async function * () { yield "a"; }) : () => AsyncGenerator<string, void, unknown>
|
||||
>async function * () { yield "a"; } : () => AsyncGenerator<string, void, unknown>
|
||||
>yield "a" : any
|
||||
>(async function * () { yield "a"; })() : AsyncGenerator<string, void, undefined>
|
||||
>(async function * () { yield "a"; }) : () => AsyncGenerator<string, void, undefined>
|
||||
>async function * () { yield "a"; } : () => AsyncGenerator<string, void, undefined>
|
||||
>yield "a" : undefined
|
||||
>"a" : "a"
|
||||
}
|
||||
async function * explicitReturnType4(): AsyncIterable<number> {
|
||||
@@ -174,10 +174,10 @@ async function * explicitReturnType6(): AsyncIterable<number> {
|
||||
|
||||
yield* (async function * () { yield "a"; })();
|
||||
>yield* (async function * () { yield "a"; })() : void
|
||||
>(async function * () { yield "a"; })() : AsyncGenerator<string, void, unknown>
|
||||
>(async function * () { yield "a"; }) : () => AsyncGenerator<string, void, unknown>
|
||||
>async function * () { yield "a"; } : () => AsyncGenerator<string, void, unknown>
|
||||
>yield "a" : any
|
||||
>(async function * () { yield "a"; })() : AsyncGenerator<string, void, undefined>
|
||||
>(async function * () { yield "a"; }) : () => AsyncGenerator<string, void, undefined>
|
||||
>async function * () { yield "a"; } : () => AsyncGenerator<string, void, undefined>
|
||||
>yield "a" : undefined
|
||||
>"a" : "a"
|
||||
}
|
||||
async function * explicitReturnType7(): AsyncIterator<number> {
|
||||
@@ -201,10 +201,10 @@ async function * explicitReturnType9(): AsyncIterator<number> {
|
||||
|
||||
yield* (async function * () { yield "a"; })();
|
||||
>yield* (async function * () { yield "a"; })() : void
|
||||
>(async function * () { yield "a"; })() : AsyncGenerator<string, void, unknown>
|
||||
>(async function * () { yield "a"; }) : () => AsyncGenerator<string, void, unknown>
|
||||
>async function * () { yield "a"; } : () => AsyncGenerator<string, void, unknown>
|
||||
>yield "a" : any
|
||||
>(async function * () { yield "a"; })() : AsyncGenerator<string, void, undefined>
|
||||
>(async function * () { yield "a"; }) : () => AsyncGenerator<string, void, undefined>
|
||||
>async function * () { yield "a"; } : () => AsyncGenerator<string, void, undefined>
|
||||
>yield "a" : undefined
|
||||
>"a" : "a"
|
||||
}
|
||||
async function * explicitReturnType10(): IterableIterator<number> {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// @lib: esnext
|
||||
|
||||
const test1: Promise<[one: number, two: string]> = (async () => {
|
||||
return [1, 'two'];
|
||||
})();
|
||||
|
||||
const test2: Promise<[one: number, two: string]> = new Promise(
|
||||
(resolve) => resolve([1, 'two']),
|
||||
);
|
||||
|
||||
const obj: { foo: [one: number, two: string] } = {
|
||||
foo: (() => [1, 'two'])()
|
||||
};
|
||||
Reference in New Issue
Block a user