Skip to content

Commit

Permalink
馃悰 fix type definition
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jan 22, 2019
1 parent 91bf895 commit 74fb529
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
63 changes: 33 additions & 30 deletions dist/abort-controller.d.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
import { EventTarget } from 'event-target-shim';
import { EventTarget } from "event-target-shim"

export declare type Events = {
abort: any;
};
export declare type EventAttributes = {
onabort: any;
};
type Events = {
abort: any

This comment has been minimized.

Copy link
@felixfbecker

felixfbecker Feb 24, 2019

Why is this any? This makes 2.0.0 a regression for TS users who used the global types before (now TypeScript will use these types)

This comment has been minimized.

Copy link
@mysticatea

mysticatea Feb 24, 2019

Author Owner

This is intentional.
AbortSignal in lib.dom.d.ts has wrong type (ProgressEvent), but I wanted compatible with AbortSignal in lib.dom.d.ts.

}
type EventAttributes = {
onabort: any
}
/**
* The signal class.
* @see https://dom.spec.whatwg.org/#abortsignal
*/
export declare class AbortSignal extends EventTarget<Events, EventAttributes> {
/**
* AbortSignal cannot be constructed directly.
*/
constructor();
/**
* Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise.
*/
readonly aborted: boolean;
declare class AbortSignal extends EventTarget<Events, EventAttributes> {
/**
* AbortSignal cannot be constructed directly.
*/
constructor()
/**
* Returns `true` if this `AbortSignal`"s `AbortController` has signaled to abort, and `false` otherwise.
*/
readonly aborted: boolean
}
/**
* The AbortController.
* @see https://dom.spec.whatwg.org/#abortcontroller
*/
export default class AbortController {
/**
* Initialize this controller.
*/
constructor();
/**
* Returns the `AbortSignal` object associated with this object.
*/
readonly signal: AbortSignal;
/**
* Abort and signal to any observers that the associated activity is to be aborted.
*/
abort(): void;
}
declare class AbortController {
/**
* Initialize this controller.
*/
constructor()
/**
* Returns the `AbortSignal` object associated with this object.
*/
readonly signal: AbortSignal
/**
* Abort and signal to any observers that the associated activity is to be aborted.
*/
abort(): void
}

export default AbortController
export { AbortController, AbortSignal }
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"lint": "eslint . --ext .ts",
"build": "run-s -s build:*",
"build:rollup": "rollup -c",
"build:dts": "dts-bundle-generator -o dist/abort-controller.d.ts src/abort-controller.ts",
"build:dts": "dts-bundle-generator -o dist/abort-controller.d.ts src/abort-controller.ts && ts-node scripts/fix-dts",
"test": "run-s -s lint test:*",
"test:mocha": "nyc mocha test/*.ts",
"test:karma": "karma start --single-run",
Expand Down
18 changes: 18 additions & 0 deletions scripts/fix-dts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import fs from "fs"

fs.writeFileSync(
"dist/abort-controller.d.ts",
[
fs
.readFileSync("dist/abort-controller.d.ts", "utf8")
.replace(/export declare type/gu, "type")
.replace(/export (?:declare|default) class/gu, "declare class")
.replace(/\t/gu, " ")
.replace(/'/gu, '"')
.replace(/;\n/gu, "\n"),
"",
"export default AbortController",
"export { AbortController, AbortSignal }",
"",
].join("\n"),
)

0 comments on commit 74fb529

Please sign in to comment.