From 324e89e9fa0f27c474d864ec2ad33d2d820675c9 Mon Sep 17 00:00:00 2001 From: George Fu Date: Thu, 30 Mar 2023 13:56:29 -0400 Subject: [PATCH] docs(abort-controller): add message about browsers (#4591) * docs(abort-controller): add message about browsers * docs(abort-controller): update packages/abort-controller/src/AbortController.ts Co-authored-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> * fix(types): global AbortController type compat --------- Co-authored-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> --- packages/abort-controller/src/AbortController.ts | 4 ++++ packages/types/package.json | 2 +- packages/types/src/abort.spec.ts | 5 +++++ packages/types/src/abort.ts | 2 +- packages/types/tsconfig.test.json | 10 ++++++++++ 5 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 packages/types/src/abort.spec.ts create mode 100644 packages/types/tsconfig.test.json diff --git a/packages/abort-controller/src/AbortController.ts b/packages/abort-controller/src/AbortController.ts index a8eba8f7be96..fbfc7cccf542 100644 --- a/packages/abort-controller/src/AbortController.ts +++ b/packages/abort-controller/src/AbortController.ts @@ -2,6 +2,10 @@ import { AbortController as IAbortController } from "@aws-sdk/types"; import { AbortSignal } from "./AbortSignal"; +/** + * This implementation was added as Node.js didn't support AbortController prior to 15.x + * Use native implementation in browsers or Node.js >=15.4.0. + */ export class AbortController implements IAbortController { public readonly signal: AbortSignal = new AbortSignal(); diff --git a/packages/types/package.json b/packages/types/package.json index d3f251c3ee3e..d0b8acefe06b 100755 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -13,7 +13,7 @@ "build:types": "tsc -p tsconfig.types.json", "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4", "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo", - "test": "exit 0" + "test": "tsc -p tsconfig.test.json" }, "author": { "name": "AWS SDK for JavaScript Team", diff --git a/packages/types/src/abort.spec.ts b/packages/types/src/abort.spec.ts new file mode 100644 index 000000000000..baf851ca492a --- /dev/null +++ b/packages/types/src/abort.spec.ts @@ -0,0 +1,5 @@ +import { AbortSignal } from "./abort"; + +// asserts that the global abortController signal is compatible with +// our signal type. +const signal: AbortSignal = new AbortController().signal; diff --git a/packages/types/src/abort.ts b/packages/types/src/abort.ts index fc58c6189d33..344e1f99abc8 100644 --- a/packages/types/src/abort.ts +++ b/packages/types/src/abort.ts @@ -23,7 +23,7 @@ export interface AbortSignal { * A function to be invoked when the action represented by this signal has * been cancelled. */ - onabort: AbortHandler | null; + onabort: AbortHandler | Function | null; } /** diff --git a/packages/types/tsconfig.test.json b/packages/types/tsconfig.test.json new file mode 100644 index 000000000000..f2b39acb80cb --- /dev/null +++ b/packages/types/tsconfig.test.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "rootDir": "src", + "noEmit": true + }, + "extends": "../../tsconfig.cjs.json", + "include": ["src/"], + "exclude": [] +}