mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
Make ts3.1 the default for task-worklet (#46932)
* Delete ts3.1/ for task-worklet It's not needed now that 3.1 is the lowest version supported by DT. * restore header * switch to export= * do not export Options type
This commit is contained in:
parent
c2859fdc14
commit
997cf64efe
12
types/task-worklet/index.d.ts
vendored
12
types/task-worklet/index.d.ts
vendored
@ -2,11 +2,10 @@
|
||||
// Project: https://github.com/developit/task-worklet, https://github.com/googlechromelabs/task-worklet
|
||||
// Definitions by: Karol Majewski <https://github.com/karol-majewski>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.9
|
||||
|
||||
declare class TaskQueue {
|
||||
declare class TaskQueue<T extends TaskQueue.TaskDescriptor = any> {
|
||||
constructor(options?: Options);
|
||||
postTask(taskName: string, ...args: any[]): TaskQueue.Task;
|
||||
postTask<U extends T = any>(taskName: U['name'], ...args: Parameters<U>): TaskQueue.Task<ReturnType<U>>;
|
||||
addModule(moduleURL: string): Promise<void>;
|
||||
}
|
||||
|
||||
@ -15,7 +14,12 @@ interface Options {
|
||||
}
|
||||
|
||||
declare namespace TaskQueue {
|
||||
interface Task<T = any> {
|
||||
interface TaskDescriptor {
|
||||
name: string;
|
||||
(...args: any): any;
|
||||
}
|
||||
|
||||
interface Task<T = unknown> {
|
||||
id: number;
|
||||
state: State;
|
||||
result: Promise<T extends PromiseLike<infer U> ? U : T>;
|
||||
|
||||
@ -1,13 +1,5 @@
|
||||
{
|
||||
"private": true,
|
||||
"types": "index",
|
||||
"typesVersions": {
|
||||
">=3.1.0-0": {
|
||||
"*": [
|
||||
"ts3.1/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"typescript": ">2.9.0"
|
||||
}
|
||||
|
||||
@ -5,17 +5,17 @@ interface Fetcher {
|
||||
(input: RequestInfo, init?: RequestInit): Promise<Response>;
|
||||
}
|
||||
|
||||
const unsafe = new TaskQueue(); // $ExpectType TaskQueue
|
||||
const withEmptyOptions = new TaskQueue({}); // $ExpectType TaskQueue
|
||||
const withValidOptions = new TaskQueue({ size: 2 }); // $ExpectType TaskQueue
|
||||
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(); // $ExpectType TaskQueue
|
||||
const queue = new TaskQueue<Fetcher>(); // $ExpectType TaskQueue<Fetcher>
|
||||
queue.addModule('/fetcher-worklet.js'); // $ExpectType Promise<void>
|
||||
const task = queue.postTask('fetch', 'https://example.com'); // $ExpectType Task
|
||||
const task = queue.postTask<Fetcher>('fetch', 'https://example.com'); // $ExpectType Task<Promise<Response>>
|
||||
|
||||
async () => {
|
||||
await task.result.then(result => {
|
||||
result; // $ExpectType any
|
||||
result; // $ExpectType Response
|
||||
});
|
||||
const id = task.id; // $ExpectType number
|
||||
const state = task.state; // $ExpectType State
|
||||
|
||||
30
types/task-worklet/ts3.1/index.d.ts
vendored
30
types/task-worklet/ts3.1/index.d.ts
vendored
@ -1,30 +0,0 @@
|
||||
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 extends PromiseLike<infer U> ? U : T>;
|
||||
}
|
||||
|
||||
export type State =
|
||||
| 'cancelled'
|
||||
| 'completed'
|
||||
| 'fulfilled'
|
||||
| 'pending'
|
||||
| 'scheduled';
|
||||
|
||||
export default TaskQueue;
|
||||
export as namespace TaskQueue;
|
||||
@ -1,25 +0,0 @@
|
||||
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 () => {
|
||||
await task.result.then(result => {
|
||||
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
|
||||
@ -1,24 +0,0 @@
|
||||
{
|
||||
"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 +0,0 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user