mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Offer different version for TypeScript >3.1
This commit is contained in:
parent
0e4eb7633c
commit
50523db106
13
types/task-worklet/index.d.ts
vendored
13
types/task-worklet/index.d.ts
vendored
@ -2,11 +2,11 @@
|
||||
// Project: https://github.com/GoogleChromeLabs/task-worklet
|
||||
// Definitions by: Karol Majewski <https://github.com/karol-majewski>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.1
|
||||
// TypeScript Version: 2.9
|
||||
|
||||
declare class TaskQueue<T extends TaskDescriptor = any> {
|
||||
declare class TaskQueue {
|
||||
constructor(options?: Options);
|
||||
postTask<U extends T = any>(taskName: U['name'], ...args: Parameters<U>): Task<ReturnType<U>>;
|
||||
postTask(taskName: string, ...args: any[]): Task;
|
||||
addModule(moduleURL: string): Promise<void>;
|
||||
}
|
||||
|
||||
@ -14,12 +14,7 @@ interface Options {
|
||||
size?: number;
|
||||
}
|
||||
|
||||
interface TaskDescriptor {
|
||||
name: string;
|
||||
(...args: any): any;
|
||||
}
|
||||
|
||||
export interface Task<T = unknown> {
|
||||
export interface Task<T = any> {
|
||||
id: number;
|
||||
state: State;
|
||||
result: Promise<T>;
|
||||
|
||||
14
types/task-worklet/package.json
Normal file
14
types/task-worklet/package.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"private": true,
|
||||
"types": "index",
|
||||
"typesVersions": {
|
||||
">=3.1.0-0": {
|
||||
"*": [
|
||||
"ts3.1/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"typescript": ">2.9.0"
|
||||
}
|
||||
}
|
||||
@ -5,16 +5,16 @@ interface Fetcher {
|
||||
(input: RequestInfo, init?: RequestInit): Promise<Response>;
|
||||
}
|
||||
|
||||
const unsafe = new TaskQueue(); // $ExpectType TaskQueue<any>
|
||||
const withEmptyOptions = new TaskQueue({}); // $ExpectType TaskQueue<any>
|
||||
const withValidOptions = new TaskQueue({ size: 2 }); // $ExpectType TaskQueue<any>
|
||||
const unsafe = new TaskQueue(); // $ExpectType TaskQueue
|
||||
const withEmptyOptions = new TaskQueue({}); // $ExpectType TaskQueue
|
||||
const withValidOptions = new TaskQueue({ size: 2 }); // $ExpectType TaskQueue
|
||||
|
||||
const queue = new TaskQueue<Fetcher>(); // $ExpectType TaskQueue<Fetcher>
|
||||
const queue = new TaskQueue(); // $ExpectType TaskQueue
|
||||
queue.addModule('/fetcher-worklet.js'); // $ExpectType Promise<void>
|
||||
const task = queue.postTask<Fetcher>('fetch', 'https://example.com'); // $ExpectType Task<Promise<Response>>
|
||||
const task = queue.postTask('fetch', 'https://example.com'); // $ExpectType Task
|
||||
|
||||
async () => {
|
||||
const result = await task.result; // $ExpectType Response
|
||||
const result = await task.result; // $ExpectType any
|
||||
const id = task.id; // $ExpectType number
|
||||
const state = task.state; // $ExpectType State
|
||||
};
|
||||
|
||||
30
types/task-worklet/ts3.1/index.d.ts
vendored
Normal file
30
types/task-worklet/ts3.1/index.d.ts
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
declare class TaskQueue<T extends TaskDescriptor = any> {
|
||||
constructor(options?: Options);
|
||||
postTask<U extends T = any>(taskName: U['name'], ...args: Parameters<U>): Task<ReturnType<U>>;
|
||||
addModule(moduleURL: string): Promise<void>;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
size?: number;
|
||||
}
|
||||
|
||||
interface TaskDescriptor {
|
||||
name: string;
|
||||
(...args: any): any;
|
||||
}
|
||||
|
||||
export interface Task<T = unknown> {
|
||||
id: number;
|
||||
state: State;
|
||||
result: Promise<T>;
|
||||
}
|
||||
|
||||
export type State =
|
||||
| 'cancelled'
|
||||
| 'completed'
|
||||
| 'fulfilled'
|
||||
| 'pending'
|
||||
| 'scheduled';
|
||||
|
||||
export default TaskQueue;
|
||||
export as namespace TaskQueue;
|
||||
23
types/task-worklet/ts3.1/task-worklet-tests.ts
Normal file
23
types/task-worklet/ts3.1/task-worklet-tests.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import TaskQueue, { Task, State } from 'task-worklet';
|
||||
|
||||
interface Fetcher {
|
||||
name: 'fetch';
|
||||
(input: RequestInfo, init?: RequestInit): Promise<Response>;
|
||||
}
|
||||
|
||||
const unsafe = new TaskQueue(); // $ExpectType TaskQueue<any>
|
||||
const withEmptyOptions = new TaskQueue({}); // $ExpectType TaskQueue<any>
|
||||
const withValidOptions = new TaskQueue({ size: 2 }); // $ExpectType TaskQueue<any>
|
||||
|
||||
const queue = new TaskQueue<Fetcher>(); // $ExpectType TaskQueue<Fetcher>
|
||||
queue.addModule('/fetcher-worklet.js'); // $ExpectType Promise<void>
|
||||
const task = queue.postTask<Fetcher>('fetch', 'https://example.com'); // $ExpectType Task<Promise<Response>>
|
||||
|
||||
async () => {
|
||||
const result = await task.result; // $ExpectType Response
|
||||
const id = task.id; // $ExpectType number
|
||||
const state = task.state; // $ExpectType State
|
||||
};
|
||||
|
||||
new TaskQueue({ size: 1, excessProperty: true }); // $ExpectError
|
||||
queue.postTask<Fetcher>('incorrect-task-name'); // $ExpectError
|
||||
24
types/task-worklet/ts3.1/tsconfig.json
Normal file
24
types/task-worklet/ts3.1/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strictFunctionTypes": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"task-worklet-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/task-worklet/ts3.1/tslint.json
Normal file
1
types/task-worklet/ts3.1/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user