mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 14:27:04 +00:00
feat: Add @ungap/weakmap (#40691)
This commit is contained in:
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// Type definitions for @ungap/weakmap 0.1
|
||||
// Project: https://github.com/ungap/weakmap#readme
|
||||
// Definitions by: ExE Boss <https://github.com/ExE-Boss>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/**
|
||||
* Based on definitions from `lib.es2015.collection` and `lib.es2015.iterable`.
|
||||
*/
|
||||
declare class WeakMap<K extends object = object, V = any> {
|
||||
constructor(entries?: ReadonlyArray<[K, V]> | null);
|
||||
constructor(iterable: Iterable<[K, V]> | null | undefined);
|
||||
|
||||
delete(key: K): boolean;
|
||||
get(key: K): V | undefined;
|
||||
has(key: K): boolean;
|
||||
set(key: K, value: V): this;
|
||||
}
|
||||
|
||||
export = WeakMap;
|
||||
export as namespace WeakMap;
|
||||
@@ -0,0 +1,22 @@
|
||||
import WeakMap = require('ungap__weakmap');
|
||||
|
||||
WeakMap; // $ExpectType typeof WeakMap
|
||||
|
||||
// $ExpectType WeakMap<object, any>
|
||||
const weakMap = new WeakMap();
|
||||
|
||||
weakMap.delete; // $ExpectType (key: object) => boolean
|
||||
weakMap.has; // $ExpectType (key: object) => boolean
|
||||
weakMap.get; // $ExpectType (key: object) => any
|
||||
weakMap.set; // $ExpectType (key: object, value: any) => WeakMap<object, any>
|
||||
|
||||
function foo<K extends object, V>(...args: Array<[K, V]>): WeakMap<K, V> {
|
||||
const weakMap = new WeakMap(arguments as Iterable<[K, V]>);
|
||||
|
||||
weakMap.delete; // $ExpectType (key: K) => boolean
|
||||
weakMap.has; // $ExpectType (key: K) => boolean
|
||||
weakMap.get; // $ExpectType (key: K) => V | undefined
|
||||
weakMap.set; // $ExpectType (key: K, value: V) => WeakMap<K, V>
|
||||
|
||||
return weakMap;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es5", "es2015.iterable"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"test/weakmap.cjs.test.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user