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:
Nathan Shively-Sanders 2020-08-21 07:56:16 -07:00 committed by GitHub
parent c2859fdc14
commit 997cf64efe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 98 deletions

View File

@ -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>;

View File

@ -1,13 +1,5 @@
{
"private": true,
"types": "index",
"typesVersions": {
">=3.1.0-0": {
"*": [
"ts3.1/*"
]
}
},
"dependencies": {
"typescript": ">2.9.0"
}

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -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"
]
}

View File

@ -1 +0,0 @@
{ "extends": "dtslint/dt.json" }