Skip to content

Commit 7dc4916

Browse files
committed
es2019.object
1 parent 00988ff commit 7dc4916

File tree

5 files changed

+60
-0
lines changed

5 files changed

+60
-0
lines changed

build/replacement.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,7 @@ export const replacement = new Map([
4141
["lib.es2015.proxy.d.ts", new Set(["ProxyHandler"])],
4242
["lib.es2015.reflect.d.ts", new Set(["Reflect"])],
4343
["lib.es2017.object.d.ts", new Set(["ObjectConstructor"])],
44+
["lib.es2018.asyncgenerator.d.ts", new Set(["AsyncGenerator"])],
45+
["lib.es2018.asynciterable.d.ts", new Set(["AsyncIterator"])],
46+
["lib.es2019.object.d.ts", new Set(["ObjectConstructor"])],
4447
]);

lib/lib.es2018.asyncgenerator.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference no-default-lib="true"/>
2+
3+
interface AsyncGenerator<T = unknown, TReturn = unknown, TNext = unknown>
4+
extends AsyncIterator<T, TReturn, TNext> {
5+
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
6+
next(...args: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
7+
return(
8+
value: TReturn | PromiseLike<TReturn>
9+
): Promise<IteratorResult<T, TReturn>>;
10+
throw(e: any): Promise<IteratorResult<T, TReturn>>;
11+
[Symbol.asyncIterator](): AsyncGenerator<T, TReturn, TNext>;
12+
}

lib/lib.es2018.asynciterable.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/// <reference no-default-lib="true"/>
2+
3+
interface AsyncIterator<T, TReturn = unknown, TNext = undefined> {
4+
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
5+
next(...args: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
6+
return?(
7+
value?: TReturn | PromiseLike<TReturn>
8+
): Promise<IteratorResult<T, TReturn>>;
9+
throw?(e?: any): Promise<IteratorResult<T, TReturn>>;
10+
}

lib/lib.es2019.object.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference no-default-lib="true"/>
2+
3+
interface ObjectConstructor {
4+
/**
5+
* Returns an object created by key-value entries for properties and methods
6+
* @param entries An iterable object that contains key-value entries for properties and methods.
7+
*/
8+
fromEntries<T extends readonly [PropertyKey, unknown]>(
9+
entries: Iterable<T>
10+
): Record<T[0], T[1]>;
11+
}

tests/es2019.object.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path="../dist/lib/lib.es2019.d.ts" />
2+
3+
import { expectType } from "tsd";
4+
5+
// ObjectConstructor
6+
{
7+
const arr1: [] = [];
8+
const obj1 = Object.fromEntries(arr1);
9+
expectType<{}>(obj1);
10+
11+
const arr2 = [
12+
["foo", 123],
13+
["bar", 456],
14+
] as const;
15+
const obj2 = Object.fromEntries(arr2);
16+
expectType<{
17+
foo: 123 | 456;
18+
bar: 123 | 456;
19+
}>(obj2);
20+
21+
const arr3: [string, number][] = [];
22+
const obj3 = Object.fromEntries(arr3);
23+
expectType<Record<string, number>>(obj3);
24+
}

0 commit comments

Comments
 (0)