From 192d9b0c9c06ef0588ee410c42bd1ed6cd37264a Mon Sep 17 00:00:00 2001 From: Yotam Mann Date: Fri, 3 May 2024 14:18:52 -0400 Subject: [PATCH] import type syntax --- Tone/core/Tone.ts | 2 +- Tone/core/clock/TransportEvent.ts | 3 +-- Tone/core/clock/TransportRepeatEvent.ts | 3 +-- Tone/core/context/BaseContext.ts | 9 ++++----- Tone/core/context/Context.ts | 9 ++++----- Tone/core/context/ContextInitialization.ts | 3 +-- Tone/core/context/DummyContext.ts | 9 ++++----- Tone/core/context/ToneWithContext.ts | 2 +- Tone/core/util/Debug.ts | 10 ++++------ Tone/core/util/Defaults.ts | 3 +-- Tone/index.ts | 8 ++++---- Tone/signal/SyncedSignal.ts | 2 +- test/helper/compare/Plot.ts | 2 +- test/helper/compare/TestAudioBuffer.ts | 2 +- tsconfig.json | 7 +++---- 15 files changed, 32 insertions(+), 42 deletions(-) diff --git a/Tone/core/Tone.ts b/Tone/core/Tone.ts index 460d40f0..644cda7b 100644 --- a/Tone/core/Tone.ts +++ b/Tone/core/Tone.ts @@ -2,7 +2,7 @@ * Tone.js * @author Yotam Mann * @license http://opensource.org/licenses/MIT MIT License - * @copyright 2014-2019 Yotam Mann + * @copyright 2014-2024 Yotam Mann */ import { version } from "../version.js"; import { theWindow } from "./context/AudioContext.js"; diff --git a/Tone/core/clock/TransportEvent.ts b/Tone/core/clock/TransportEvent.ts index 451164a2..dde35a73 100644 --- a/Tone/core/clock/TransportEvent.ts +++ b/Tone/core/clock/TransportEvent.ts @@ -1,7 +1,6 @@ import { Seconds, Ticks } from "../type/Units.js"; import { noOp } from "../util/Interface.js"; - -type Transport = import("../clock/Transport").TransportClass; +import type { TransportClass as Transport } from "./Transport.js"; export interface TransportEventOptions { callback: (time: number) => void; diff --git a/Tone/core/clock/TransportRepeatEvent.ts b/Tone/core/clock/TransportRepeatEvent.ts index 107b0e56..3fd90268 100644 --- a/Tone/core/clock/TransportRepeatEvent.ts +++ b/Tone/core/clock/TransportRepeatEvent.ts @@ -3,8 +3,7 @@ import { TicksClass } from "../type/Ticks.js"; import { Seconds, Ticks, Time } from "../type/Units.js"; import { TransportEvent, TransportEventOptions } from "./TransportEvent.js"; import { GT, LT } from "../util/Math.js"; - -type Transport = import("../clock/Transport").TransportClass; +import type { TransportClass as Transport } from "./Transport.js"; interface TransportRepeatEventOptions extends TransportEventOptions { interval: Ticks; diff --git a/Tone/core/context/BaseContext.ts b/Tone/core/context/BaseContext.ts index ccb5c83b..fbd1915f 100644 --- a/Tone/core/context/BaseContext.ts +++ b/Tone/core/context/BaseContext.ts @@ -1,11 +1,10 @@ import { Seconds } from "../type/Units.js"; import { Emitter } from "../util/Emitter.js"; import { AnyAudioContext } from "./AudioContext.js"; - -type Draw = import("../util/Draw").DrawClass; -type Destination = import("./Destination").DestinationClass; -type Transport = import("../clock/Transport").TransportClass; -type Listener = import("./Listener").ListenerClass; +import type { DrawClass as Draw } from "../util/Draw.js"; +import type { DestinationClass as Destination } from "./Destination.js"; +import type { TransportClass as Transport } from "../clock/Transport.js"; +import type { ListenerClass as Listener } from "./Listener.js"; // these are either not used in Tone.js or deprecated and not implemented. export type ExcludedFromBaseAudioContext = diff --git a/Tone/core/context/Context.ts b/Tone/core/context/Context.ts index e9841aec..7c30f459 100644 --- a/Tone/core/context/Context.ts +++ b/Tone/core/context/Context.ts @@ -12,11 +12,10 @@ import { import { closeContext, initializeContext } from "./ContextInitialization.js"; import { BaseContext, ContextLatencyHint } from "./BaseContext.js"; import { assert } from "../util/Debug.js"; - -type Transport = import("../clock/Transport").TransportClass; -type Destination = import("./Destination").DestinationClass; -type Listener = import("./Listener").ListenerClass; -type Draw = import("../util/Draw").DrawClass; +import type { DrawClass as Draw } from "../util/Draw.js"; +import type { DestinationClass as Destination } from "./Destination.js"; +import type { TransportClass as Transport } from "../clock/Transport.js"; +import type { ListenerClass as Listener } from "./Listener.js"; export interface ContextOptions { clockSource: TickerClockSource; diff --git a/Tone/core/context/ContextInitialization.ts b/Tone/core/context/ContextInitialization.ts index fb4f7192..87e8f326 100644 --- a/Tone/core/context/ContextInitialization.ts +++ b/Tone/core/context/ContextInitialization.ts @@ -1,8 +1,7 @@ //------------------------------------- // INITIALIZING NEW CONTEXT //------------------------------------- - -type Context = import("./Context").Context; +import type { Context } from "./Context.js"; /** * Array of callbacks to invoke when a new context is created diff --git a/Tone/core/context/DummyContext.ts b/Tone/core/context/DummyContext.ts index cff15a0f..fe456e84 100644 --- a/Tone/core/context/DummyContext.ts +++ b/Tone/core/context/DummyContext.ts @@ -1,11 +1,10 @@ import { BaseContext } from "./BaseContext.js"; import { Seconds } from "../type/Units.js"; import { AnyAudioContext } from "./AudioContext.js"; - -type Draw = import("../util/Draw").DrawClass; -type Destination = import("./Destination").DestinationClass; -type Transport = import("../clock/Transport").TransportClass; -type Listener = import("./Listener").ListenerClass; +import type { DrawClass as Draw } from "../util/Draw.js"; +import type { DestinationClass as Destination } from "./Destination.js"; +import type { TransportClass as Transport } from "../clock/Transport.js"; +import type { ListenerClass as Listener } from "./Listener.js"; export class DummyContext extends BaseContext { //--------------------------- diff --git a/Tone/core/context/ToneWithContext.ts b/Tone/core/context/ToneWithContext.ts index 7239af0a..22fee153 100644 --- a/Tone/core/context/ToneWithContext.ts +++ b/Tone/core/context/ToneWithContext.ts @@ -19,7 +19,7 @@ import { isUndef, } from "../util/TypeCheck.js"; import { BaseContext } from "./BaseContext.js"; -import type { TransportClass } from "../clock/Transport"; +import type { TransportClass } from "../clock/Transport.js"; /** * A unit which process audio diff --git a/Tone/core/util/Debug.ts b/Tone/core/util/Debug.ts index d1d32844..a1fcc8f1 100644 --- a/Tone/core/util/Debug.ts +++ b/Tone/core/util/Debug.ts @@ -1,4 +1,6 @@ import { isUndef } from "./TypeCheck.js"; +import type { BaseContext } from "../context/BaseContext.js"; +import type { Time } from "../type/Units.js"; /** * Assert that the statement is true, otherwise invoke the error. @@ -25,9 +27,7 @@ export function assertRange(value: number, gte: number, lte = Infinity): void { /** * Warn if the context is not running. */ -export function assertContextRunning( - context: import("../context/BaseContext").BaseContext -): void { +export function assertContextRunning(context: BaseContext): void { // add a warning if the context is not started if (!context.isOffline && context.state !== "running") { warn( @@ -52,9 +52,7 @@ export function enterScheduledCallback(insideCallback: boolean): void { /** * Make sure that a time was passed into */ -export function assertUsedScheduleTime( - time?: import("../type/Units").Time -): void { +export function assertUsedScheduleTime(time?: Time): void { if ( isUndef(time) && isInsideScheduledCallback && diff --git a/Tone/core/util/Defaults.ts b/Tone/core/util/Defaults.ts index 27392909..0c422fe4 100644 --- a/Tone/core/util/Defaults.ts +++ b/Tone/core/util/Defaults.ts @@ -4,8 +4,7 @@ import { isAudioParam, } from "./AdvancedTypeCheck.js"; import { isDefined, isObject, isUndef } from "./TypeCheck.js"; - -type BaseToneOptions = import("../Tone").BaseToneOptions; +import type { BaseToneOptions } from "../Tone.js"; /** * Some objects should not be merged diff --git a/Tone/index.ts b/Tone/index.ts index a6a1f797..ea59c99e 100644 --- a/Tone/index.ts +++ b/Tone/index.ts @@ -7,10 +7,10 @@ import { ToneAudioBuffer } from "./core/context/ToneAudioBuffer.js"; export { start } from "./core/Global.js"; import { Seconds } from "./core/type/Units.js"; export { supported } from "./core/context/AudioContext.js"; -import type { TransportClass } from "./core/clock/Transport"; -import type { DestinationClass } from "./core/context/Destination"; -import type { DrawClass } from "./core/util/Draw"; -import type { ListenerClass } from "./core/context/Listener"; +import type { TransportClass } from "./core/clock/Transport.js"; +import type { DestinationClass } from "./core/context/Destination.js"; +import type { DrawClass } from "./core/util/Draw.js"; +import type { ListenerClass } from "./core/context/Listener.js"; /** * The current audio context time of the global {@link BaseContext}. diff --git a/Tone/signal/SyncedSignal.ts b/Tone/signal/SyncedSignal.ts index 4bd41a30..be373f80 100644 --- a/Tone/signal/SyncedSignal.ts +++ b/Tone/signal/SyncedSignal.ts @@ -11,7 +11,7 @@ import { optionsFromArguments } from "../core/util/Defaults.js"; import { TransportTimeClass } from "../core/type/TransportTime.js"; import { ToneConstantSource } from "./ToneConstantSource.js"; import { OutputNode } from "../core/context/ToneAudioNode.js"; -import type { TransportClass } from "../core/clock/Transport"; +import type { TransportClass } from "../core/clock/Transport.js"; /** * Adds the ability to synchronize the signal to the {@link TransportClass} diff --git a/test/helper/compare/Plot.ts b/test/helper/compare/Plot.ts index 9471c1a5..8b22aa72 100644 --- a/test/helper/compare/Plot.ts +++ b/test/helper/compare/Plot.ts @@ -1,6 +1,6 @@ import { analyze } from "./Spectrum.js"; import { TestAudioBuffer } from "./TestAudioBuffer.js"; -import type { ToneAudioBuffer } from "../../../Tone/core/context/ToneAudioBuffer"; +import type { ToneAudioBuffer } from "../../../Tone/core/context/ToneAudioBuffer.js"; import plotly from "plotly.js-dist"; import array2d from "array2d"; diff --git a/test/helper/compare/TestAudioBuffer.ts b/test/helper/compare/TestAudioBuffer.ts index 3b332cbc..0ce91fc1 100644 --- a/test/helper/compare/TestAudioBuffer.ts +++ b/test/helper/compare/TestAudioBuffer.ts @@ -1,5 +1,5 @@ import toWav from "audiobuffer-to-wav"; -import type { ToneAudioBuffer } from "../../../Tone/core/context/ToneAudioBuffer"; +import type { ToneAudioBuffer } from "../../../Tone/core/context/ToneAudioBuffer.js"; export class TestAudioBuffer { static async fromUrl( diff --git a/tsconfig.json b/tsconfig.json index ac89cb39..64564a5f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,23 +3,22 @@ "compilerOptions": { "strictNullChecks": true, "target": "ES6", - "module": "ES2015", + "module": "Node16", "noImplicitAny": false, "importHelpers": true, "noUnusedLocals": false, "removeComments": false, "outDir": "./build/esm", - "verbatimModuleSyntax" : false, "sourceMap": true, "esModuleInterop": true, "skipLibCheck": true, - "moduleResolution": "Bundler", + "moduleResolution": "Node16", "strictPropertyInitialization": true, "downlevelIteration": true, "experimentalDecorators": true, "lib": ["es6", "dom", "es2015"], "baseUrl": "./", - "rootDir": "./", + "rootDir": "./" }, "include": ["Tone/**/*.ts", "test/**/*.ts"], "exclude": ["node_modules", "test/integration/**"]