diff --git a/Tone/component/channel/Panner3D.test.ts b/Tone/component/channel/Panner3D.test.ts index 46e593fc2..27374a4c7 100644 --- a/Tone/component/channel/Panner3D.test.ts +++ b/Tone/component/channel/Panner3D.test.ts @@ -68,8 +68,8 @@ describe("Panner3D", () => { const panner = new Panner3D(); for (const v in values) { if (v in values) { - panner[v] = values[v]; - expect(panner[v]).to.equal(values[v]); + (panner as any)[v] = (values as any)[v]; + expect((panner as any)[v]).to.equal((values as any)[v]); } } panner.dispose(); diff --git a/Tone/component/channel/Recorder.test.ts b/Tone/component/channel/Recorder.test.ts index 0d4a02202..3e07e4309 100644 --- a/Tone/component/channel/Recorder.test.ts +++ b/Tone/component/channel/Recorder.test.ts @@ -35,10 +35,11 @@ describe("Recorder", () => { context: testContext, }); for (const member in rec) { - if (rec[member] instanceof ToneWithContext) { - expect(rec[member].context, `member: ${member}`).to.equal( - testContext - ); + if ((rec as any)[member] instanceof ToneWithContext) { + expect( + (rec as any)[member].context, + `member: ${member}` + ).to.equal(testContext); } } testContext.dispose(); @@ -47,7 +48,7 @@ describe("Recorder", () => { }); }); - function wait(time) { + function wait(time: number) { return new Promise((done) => setTimeout(done, time)); } diff --git a/Tone/component/envelope/Envelope.ts b/Tone/component/envelope/Envelope.ts index 280972b00..a142d4bc0 100644 --- a/Tone/component/envelope/Envelope.ts +++ b/Tone/component/envelope/Envelope.ts @@ -242,7 +242,8 @@ export class Envelope extends ToneAudioNode { // look up the name in the curves array let curveName: EnvelopeCurveName; for (curveName in EnvelopeCurves) { - if (EnvelopeCurves[curveName][direction] === curve) { + const curveDef = EnvelopeCurves[curveName]; + if (isObject(curveDef) && (curveDef as any)[direction] === curve) { return curveName; } } diff --git a/Tone/component/filter/PhaseShiftAllpass.test.ts b/Tone/component/filter/PhaseShiftAllpass.test.ts index 2737cd3e7..7c825b38c 100644 --- a/Tone/component/filter/PhaseShiftAllpass.test.ts +++ b/Tone/component/filter/PhaseShiftAllpass.test.ts @@ -26,7 +26,7 @@ describe("PhaseShiftAllpass", () => { it("generates correct values with the phase shifted channel", () => { return CompareToFile( - (context) => { + (context: any) => { // create impulse with 5 samples offset const constantNode = context.createConstantSource(); constantNode.start(0); @@ -56,7 +56,7 @@ describe("PhaseShiftAllpass", () => { it("generates correct values with the offset90 channel", () => { return CompareToFile( - (context) => { + (context: any) => { // create impulse with 5 samples offset const constantNode = context.createConstantSource(); constantNode.start(0); diff --git a/Tone/core/clock/Transport.ts b/Tone/core/clock/Transport.ts index e12a42f6d..76ff42edd 100644 --- a/Tone/core/clock/Transport.ts +++ b/Tone/core/clock/Transport.ts @@ -158,7 +158,12 @@ export class TransportInstance /** * All the events in an object to keep track by ID */ - private _scheduledEvents = {}; + private _scheduledEvents: { + [key: string]: { + event: TransportEvent; + timeline: Timeline; + }; + } = {}; /** * The scheduled events. @@ -536,7 +541,7 @@ export class TransportInstance get loop(): boolean { return this._loop.get(this.now()); } - set loop(loop) { + set loop(loop: boolean) { this._loop.set(loop, this.now()); } diff --git a/Tone/core/context/Context.test.ts b/Tone/core/context/Context.test.ts index a44bf2f22..16d796864 100644 --- a/Tone/core/context/Context.test.ts +++ b/Tone/core/context/Context.test.ts @@ -125,7 +125,7 @@ describe("Context", () => { }); context("clockSource", () => { - let ctx; + let ctx: Context; beforeEach(() => { ctx = new Context(); return ctx.resume(); @@ -168,7 +168,7 @@ describe("Context", () => { }); }); context("setTimeout", () => { - let ctx; + let ctx: Context; beforeEach(() => { ctx = new Context(); return ctx.resume(); @@ -248,7 +248,7 @@ describe("Context", () => { }); context("setInterval", () => { - let ctx; + let ctx: Context; beforeEach(() => { ctx = new Context(); return ctx.resume(); @@ -320,7 +320,7 @@ describe("Context", () => { }); context("get/set", () => { - let ctx; + let ctx: Context; beforeEach(() => { ctx = new Context(); return ctx.resume(); @@ -356,7 +356,7 @@ describe("Context", () => { }); context("Methods", () => { - let ctx; + let ctx: Context; beforeEach(() => { ctx = new Context(); return ctx.resume(); diff --git a/Tone/core/context/Context.ts b/Tone/core/context/Context.ts index 9bfcb8a70..f462601f7 100644 --- a/Tone/core/context/Context.ts +++ b/Tone/core/context/Context.ts @@ -560,9 +560,9 @@ export class Context extends BaseContext { this._ticker.dispose(); this._timeouts.dispose(); this._timeoutMap.clear(); - Object.keys(this._constants).map((val) => - this._constants[val].disconnect() - ); + this._constants.forEach((constant) => { + constant.disconnect(); + }); this.close(); return this; } diff --git a/Tone/core/context/Param.test.ts b/Tone/core/context/Param.test.ts index 70d8c2f2d..419f20d2d 100644 --- a/Tone/core/context/Param.test.ts +++ b/Tone/core/context/Param.test.ts @@ -54,8 +54,8 @@ describe("Param", () => { context("Scheduling Curves", () => { const sampleRate = 11025; - function matchesOutputCurve(param, outBuffer): void { - outBuffer.toArray()[0].forEach((sample, index) => { + function matchesOutputCurve(param: any, outBuffer: any): void { + outBuffer.toArray()[0].forEach((sample: number, index: number) => { try { expect( param.getValueAtTime(index / sampleRate) @@ -277,7 +277,7 @@ describe("Param", () => { context("apply", () => { it("can apply a scheduled curve", async () => { - let sig; + let sig: any; const buffer = await Offline((context) => { const signal = new Signal(); sig = signal; @@ -303,7 +303,7 @@ describe("Param", () => { }); it("can apply a scheduled curve that starts with a setTargetAtTime", async () => { - let sig; + let sig: any; const buffer = await Offline((context) => { const signal = new Signal(); sig = signal; @@ -324,7 +324,7 @@ describe("Param", () => { }); it("can apply a scheduled curve that starts with a setTargetAtTime and then schedules other things", async () => { - let sig; + let sig: any; const buffer = await Offline((context) => { const signal = new Signal(); sig = signal; @@ -433,7 +433,7 @@ describe("Param", () => { }); context("min/maxValue", () => { - function testMinMaxValue(units: UnitName, min, max): void { + function testMinMaxValue(units: UnitName, min: any, max: any): void { it(`has proper min/max for ${units}`, () => { const source = audioContext.createConstantSource(); source.connect(audioContext.rawContext.destination); @@ -611,8 +611,8 @@ describe("Param", () => { units, }); param.setValueAtTime(value0, 0); - param[method](value1, 0.01); - param[method](value2, 0.02); + (param as any)[method](value1, 0.01); + (param as any)[method](value2, 0.02); expect(param.getValueAtTime(0)).to.be.closeTo( value0, @@ -692,8 +692,8 @@ describe("Param", () => { units, value: value0, }); - param[method](value1, 0.009, 0); - param[method](value2, 0.01, 0.01); + (param as any)[method](value1, 0.009, 0); + (param as any)[method](value2, 0.01, 0.01); expect(param.getValueAtTime(0)).to.be.closeTo( value0, diff --git a/Tone/core/context/ToneAudioBuffer.test.ts b/Tone/core/context/ToneAudioBuffer.test.ts index 55b5de5fe..0f146a4d2 100644 --- a/Tone/core/context/ToneAudioBuffer.test.ts +++ b/Tone/core/context/ToneAudioBuffer.test.ts @@ -232,13 +232,13 @@ describe("ToneAudioBuffer", () => { it("can reverse a buffer", (done) => { const buffer = new ToneAudioBuffer(testFile, () => { - const buffArray = buffer.get() as AudioBuffer; + const buffArray = buffer.get() as any; const lastSample = buffArray[buffArray.length - 1]; buffer.reverse = true; - expect((buffer.get() as AudioBuffer)[0]).to.equal(lastSample); + expect((buffer.get() as any)[0]).to.equal(lastSample); // setting reverse again has no effect buffer.reverse = true; - expect((buffer.get() as AudioBuffer)[0]).to.equal(lastSample); + expect((buffer.get() as any)[0]).to.equal(lastSample); buffer.dispose(); done(); }); @@ -292,7 +292,7 @@ describe("ToneAudioBuffer", () => { arr[0][0] = 0.5; buffer.fromArray(arr); expect(buffer.toArray(0)[0]).to.equal(0.5); - expect(buffer.toArray()[0][0]).to.equal(0.5); + expect((buffer.toArray() as any)[0][0]).to.equal(0.5); // with a selected channel expect(buffer.toArray(0)[0]).to.equal(0.5); buffer.dispose(); diff --git a/Tone/core/context/ToneWithContext.ts b/Tone/core/context/ToneWithContext.ts index 5ee9511aa..bb67391a6 100644 --- a/Tone/core/context/ToneWithContext.ts +++ b/Tone/core/context/ToneWithContext.ts @@ -154,8 +154,8 @@ export abstract class ToneWithContext< const options = this.get(); // remove attributes from the prop that are not in the partial Object.keys(options).forEach((name) => { - if (isUndef(props[name])) { - delete options[name]; + if (isUndef((props as any)[name])) { + delete (options as any)[name]; } }); return options; @@ -171,16 +171,16 @@ export abstract class ToneWithContext< const defaults = getDefaultsFromInstance(this) as Options; Object.keys(defaults).forEach((attribute) => { if (Reflect.has(this, attribute)) { - const member = this[attribute]; + const member = (this as any)[attribute]; if ( isDefined(member) && isDefined(member.value) && isDefined(member.setValueAtTime) ) { - defaults[attribute] = member.value; + (defaults as any)[attribute] = member.value; } else if (member instanceof ToneWithContext) { - defaults[attribute] = member._getPartialProperties( - defaults[attribute] + (defaults as any)[attribute] = member._getPartialProperties( + (defaults as any)[attribute] ); // otherwise make sure it's a serializable type } else if ( @@ -189,10 +189,10 @@ export abstract class ToneWithContext< isString(member) || isBoolean(member) ) { - defaults[attribute] = member; + (defaults as any)[attribute] = member; } else { // remove all undefined and unserializable attributes - delete defaults[attribute]; + delete (defaults as any)[attribute]; } } }); @@ -214,20 +214,30 @@ export abstract class ToneWithContext< */ set(props: RecursivePartial): this { Object.keys(props).forEach((attribute) => { - if (Reflect.has(this, attribute) && isDefined(this[attribute])) { + if ( + Reflect.has(this, attribute) && + isDefined((this as any)[attribute]) + ) { if ( - this[attribute] && - isDefined(this[attribute].value) && - isDefined(this[attribute].setValueAtTime) + (this as any)[attribute] && + isDefined((this as any)[attribute].value) && + isDefined((this as any)[attribute].setValueAtTime) ) { // small optimization - if (this[attribute].value !== props[attribute]) { - this[attribute].value = props[attribute]; + if ( + (this as any)[attribute].value !== + (props as any)[attribute] + ) { + (this as any)[attribute].value = (props as any)[ + attribute + ]; } - } else if (this[attribute] instanceof ToneWithContext) { - this[attribute].set(props[attribute]); + } else if ( + (this as any)[attribute] instanceof ToneWithContext + ) { + (this as any)[attribute].set((props as any)[attribute]); } else { - this[attribute] = props[attribute]; + (this as any)[attribute] = (props as any)[attribute]; } } }); diff --git a/Tone/core/type/Frequency.ts b/Tone/core/type/Frequency.ts index 0e206b964..67765fd08 100644 --- a/Tone/core/type/Frequency.ts +++ b/Tone/core/type/Frequency.ts @@ -77,7 +77,7 @@ export class FrequencyClass extends TimeClass< if (this.defaultUnits === "midi") { return noteNumber; } else { - return FrequencyClass.mtof(noteNumber); + return FrequencyClass.mtof(noteNumber as any); } }, }, @@ -247,7 +247,7 @@ export class FrequencyClass extends TimeClass< * Note to scale index. * @hidden */ -const noteToScaleIndex = { +const noteToScaleIndex: Record = { cbbb: -3, cbb: -2, cb: -1, diff --git a/Tone/core/type/TimeBase.ts b/Tone/core/type/TimeBase.ts index bf99f07f3..2cf665eef 100644 --- a/Tone/core/type/TimeBase.ts +++ b/Tone/core/type/TimeBase.ts @@ -206,8 +206,8 @@ export abstract class TimeBaseClass< } else if (isObject(this._val)) { let total = 0; for (const typeName in this._val) { - if (isDefined(this._val[typeName])) { - const quantity = this._val[typeName]; + if (isDefined((this._val as any)[typeName])) { + const quantity = (this._val as any)[typeName]; const time = // @ts-ignore new this.constructor(this.context, typeName).valueOf() * diff --git a/Tone/core/util/Defaults.ts b/Tone/core/util/Defaults.ts index 8160a3c2d..2beac5dc8 100644 --- a/Tone/core/util/Defaults.ts +++ b/Tone/core/util/Defaults.ts @@ -43,18 +43,18 @@ export function deepMerge(target: any, ...sources: any[]): any { const source = sources.shift(); if (isObject(target) && isObject(source)) { - for (const key in source) { - if (noCopy(key, source[key])) { - target[key] = source[key]; - } else if (isObject(source[key])) { - if (!target[key]) { - Object.assign(target, { [key]: {} }); + Object.keys(source).forEach((key) => { + if (noCopy(key, (source as any)[key])) { + (target as any)[key] = (source as any)[key]; + } else if (isObject((source as any)[key])) { + if (!(target as any)[key]) { + (target as any)[key] = {}; } - deepMerge(target[key], source[key] as any); + deepMerge((target as any)[key], (source as any)[key]); } else { - Object.assign(target, { [key]: source[key] as any }); + (target as any)[key] = (source as any)[key]; } - } + }); } // @ts-ignore return deepMerge(target, ...sources); @@ -141,10 +141,11 @@ export function omitFromObject( obj: T, omit: O ): Omit { + const result: any = Object.assign({}, obj); omit.forEach((prop) => { - if (Reflect.has(obj, prop)) { - delete obj[prop]; + if (Reflect.has(result, prop)) { + delete result[prop]; } }); - return obj; + return result; } diff --git a/Tone/core/util/Timeline.ts b/Tone/core/util/Timeline.ts index eddf08acd..6cfe2963e 100644 --- a/Tone/core/util/Timeline.ts +++ b/Tone/core/util/Timeline.ts @@ -292,18 +292,18 @@ export class Timeline extends Tone { let beginning = 0; const len = this._timeline.length; let end = len; - if (len > 0 && this._timeline[len - 1][param] <= time) { + if (len > 0 && (this._timeline[len - 1] as any)[param] <= time) { return len - 1; } while (beginning < end) { // calculate the midpoint for roughly equal partition let midPoint = Math.floor(beginning + (end - beginning) / 2); - const event = this._timeline[midPoint]; - const nextEvent = this._timeline[midPoint + 1]; + const event = this._timeline[midPoint] as any; + const nextEvent = this._timeline[midPoint + 1] as any; if (EQ(event[param], time)) { // choose the last one that has the same time for (let i = midPoint; i < this._timeline.length; i++) { - const testEvent = this._timeline[i]; + const testEvent = this._timeline[i] as any; if (EQ(testEvent[param], time)) { midPoint = i; } else { diff --git a/Tone/event/Loop.test.ts b/Tone/event/Loop.test.ts index cf2ed9782..24f5bb423 100644 --- a/Tone/event/Loop.test.ts +++ b/Tone/event/Loop.test.ts @@ -234,7 +234,7 @@ describe("Loop", () => { it("loops for the specified interval", async () => { let invoked = false; await Offline(({ transport }) => { - let lastCall; + let lastCall: number; new Loop({ interval: "8n", callback: (time) => { @@ -282,7 +282,7 @@ describe("Loop", () => { it("can adjust the playbackRate", async () => { let invoked = false; await Offline(({ transport }) => { - let lastCall; + let lastCall: number; const loop = new Loop({ playbackRate: 2, interval: 0.5, diff --git a/Tone/event/Part.test.ts b/Tone/event/Part.test.ts index aa44f10a5..96da232f1 100644 --- a/Tone/event/Part.test.ts +++ b/Tone/event/Part.test.ts @@ -534,7 +534,7 @@ describe("Part", () => { it("can be set to loop at a specific interval", async () => { let invoked = false; await Offline(({ transport }) => { - let lastCall; + let lastCall: number; const part = new Part({ events: [0], loop: true, @@ -875,7 +875,7 @@ describe("Part", () => { it("can adjust the playbackRate", async () => { let invoked = false; await Offline(({ transport }) => { - let lastCall; + let lastCall: number; new Part({ events: [0, 0.5], loop: true, @@ -897,7 +897,7 @@ describe("Part", () => { it("can adjust the playbackRate after starting", async () => { let invoked = false; await Offline(({ transport }) => { - let lastCall; + let lastCall: number; const part = new Part({ events: [0, 0.25], loop: true, diff --git a/Tone/event/Part.ts b/Tone/event/Part.ts index b8d9f59be..da0c6cdaa 100644 --- a/Tone/event/Part.ts +++ b/Tone/event/Part.ts @@ -368,7 +368,7 @@ export class Part extends ToneEvent { */ private _setAll(attr: string, value: any): void { this._forEach((event) => { - event[attr] = value; + (event as any)[attr] = value; }); } diff --git a/Tone/event/Sequence.test.ts b/Tone/event/Sequence.test.ts index 4098dc348..f85a827c0 100644 --- a/Tone/event/Sequence.test.ts +++ b/Tone/event/Sequence.test.ts @@ -408,7 +408,7 @@ describe("Sequence", () => { it("can adjust the playbackRate", async () => { let invoked = false; await Offline(({ transport }) => { - let lastCall; + let lastCall: number; new Sequence({ events: [0, 1], playbackRate: 2, @@ -429,7 +429,7 @@ describe("Sequence", () => { it("adjusts speed of subsequences", async () => { let invoked = false; await Offline(({ transport }) => { - let lastCall; + let lastCall: number; new Sequence({ events: [ [0, 1], @@ -453,7 +453,7 @@ describe("Sequence", () => { it("can adjust the playbackRate after starting", async () => { let invoked = false; await Offline(({ transport }) => { - let lastCall; + let lastCall: number; const seq = new Sequence({ events: [0, 1], playbackRate: 1, diff --git a/Tone/event/Sequence.ts b/Tone/event/Sequence.ts index 4d7960ab0..648142289 100644 --- a/Tone/event/Sequence.ts +++ b/Tone/event/Sequence.ts @@ -167,7 +167,7 @@ export class Sequence extends ToneEvent { return new Proxy(array, { get: (target: any[], property: PropertyKey): any => { // property is index in this case - return target[property]; + return (target as any)[property]; }, set: ( target: any[], @@ -176,12 +176,12 @@ export class Sequence extends ToneEvent { ): boolean => { if (isString(property) && isFinite(parseInt(property, 10))) { if (isArray(value)) { - target[property] = this._createSequence(value); + (target as any)[property] = this._createSequence(value); } else { - target[property] = value; + (target as any)[property] = value; } } else { - target[property] = value; + (target as any)[property] = value; } this._eventsUpdated(); // return true to accept the changes diff --git a/Tone/event/ToneEvent.test.ts b/Tone/event/ToneEvent.test.ts index 0d99fdb99..570549f21 100644 --- a/Tone/event/ToneEvent.test.ts +++ b/Tone/event/ToneEvent.test.ts @@ -242,7 +242,7 @@ describe("ToneEvent", () => { it("can be set to loop at a specific interval", async () => { await Offline(({ transport }) => { - let lastCall; + let lastCall: number; new ToneEvent({ callback(time): void { if (lastCall) { @@ -259,7 +259,7 @@ describe("ToneEvent", () => { it("can adjust the loop duration after starting", () => { return Offline(({ transport }) => { - let lastCall; + let lastCall: number; const note = new ToneEvent({ loop: true, loopEnd: 0.5, @@ -416,7 +416,7 @@ describe("ToneEvent", () => { context("playbackRate and humanize", () => { it("can adjust the playbackRate", async () => { await Offline(({ transport }) => { - let lastCall; + let lastCall: number; new ToneEvent({ loop: true, loopEnd: 0.5, @@ -434,7 +434,7 @@ describe("ToneEvent", () => { it("can adjust the playbackRate after starting", async () => { await Offline(({ transport }) => { - let lastCall; + let lastCall: number; const note = new ToneEvent({ loop: true, loopEnd: 0.25, @@ -454,7 +454,7 @@ describe("ToneEvent", () => { it("can humanize the callback by some amount", async () => { await Offline(({ transport }) => { - let lastCall; + let lastCall: number; const note = new ToneEvent({ humanize: 0.05, loop: true, diff --git a/Tone/event/ToneEvent.ts b/Tone/event/ToneEvent.ts index 2b095cb7c..2f8827228 100644 --- a/Tone/event/ToneEvent.ts +++ b/Tone/event/ToneEvent.ts @@ -202,8 +202,8 @@ export class ToneEvent extends ToneWithContext< event.id = this.context.transport.scheduleRepeat( this._tick.bind(this), interval, - new TicksClass(this.context, startTick), - duration + new TicksClass(this.context, startTick) as any, + duration as any ); } else { event.id = this.context.transport.schedule( diff --git a/Tone/fromContext.ts b/Tone/fromContext.ts index a2383d096..0dac2f78f 100644 --- a/Tone/fromContext.ts +++ b/Tone/fromContext.ts @@ -34,8 +34,11 @@ type ToneObject = { /** * Bind the TimeBaseClass to the context */ -function bindTypeClass(context: Context, type) { - return (...args: unknown[]) => new type(context, ...args); +function bindTypeClass any>( + context: Context, + type: T +) { + return (...args: any[]) => new type(context, ...args); } /** diff --git a/Tone/instrument/Instrument.ts b/Tone/instrument/Instrument.ts index 82d9c710e..387432186 100644 --- a/Tone/instrument/Instrument.ts +++ b/Tone/instrument/Instrument.ts @@ -116,8 +116,10 @@ export abstract class Instrument< * @param timePosition What position the time argument appears in */ protected _syncMethod(method: string, timePosition: number): void { - const originalMethod = (this["_original_" + method] = this[method]); - this[method] = (...args: any[]) => { + const originalMethod = ((this as any)["_original_" + method] = (this as any)[ + method + ]); + (this as any)[method] = (...args: any[]) => { const time = args[timePosition]; const id = this.context.transport.schedule((t) => { args[timePosition] = t; diff --git a/Tone/instrument/MembraneSynth.test.ts b/Tone/instrument/MembraneSynth.test.ts index ada452254..5061c201c 100644 --- a/Tone/instrument/MembraneSynth.test.ts +++ b/Tone/instrument/MembraneSynth.test.ts @@ -81,14 +81,13 @@ describe("MembraneSynth", () => { it("Finds correct maximum note frequency", () => { const drumSynth = new MembraneSynth(); - const hertz = 65.4; // C2 + const hertz = 65.4; // C2 drumSynth.octaves = 8; - const maxNote = hertz * Math.pow(2, drumSynth.octaves); - expect(maxNote).to.equal(16742.4); // C2 + 8 octaves + const maxNote = hertz * Math.pow(2, drumSynth.octaves); + expect(maxNote).to.equal(16742.4); // C2 + 8 octaves drumSynth.dispose(); }); - it("can be constructed with an options object", () => { const drumSynth = new MembraneSynth({ envelope: { diff --git a/Tone/instrument/Sampler.ts b/Tone/instrument/Sampler.ts index 5a625079f..b814eab97 100644 --- a/Tone/instrument/Sampler.ts +++ b/Tone/instrument/Sampler.ts @@ -141,7 +141,8 @@ export class Sampler extends Instrument { ); super(options); - const urlMap = {}; + const urlMap: { [key: number]: string | ToneAudioBuffer | AudioBuffer } = + {}; Object.keys(options.urls).forEach((note) => { const noteNumber = parseInt(note, 10); assert( @@ -419,7 +420,7 @@ export class Sampler extends Instrument { get loopStart(): Time { return this._loopStart; } - set loopStart(loopStart) { + set loopStart(loopStart: Time) { this._loopStart = loopStart; this._providedMidiNotes.forEach((midiNote) => { const buffer = this._buffers.get(midiNote); @@ -441,7 +442,7 @@ export class Sampler extends Instrument { get loopEnd(): Time { return this._loopEnd; } - set loopEnd(loopEnd) { + set loopEnd(loopEnd: Time) { this._loopEnd = loopEnd; this._providedMidiNotes.forEach((midiNote) => { const buffer = this._buffers.get(midiNote); @@ -471,7 +472,7 @@ export class Sampler extends Instrument { get loop(): boolean { return this._loop; } - set loop(loop) { + set loop(loop: boolean) { // if no change, do nothing if (this._loop === loop) { return; diff --git a/Tone/signal/SyncedSignal.test.ts b/Tone/signal/SyncedSignal.test.ts index accb82088..6dbd11303 100644 --- a/Tone/signal/SyncedSignal.test.ts +++ b/Tone/signal/SyncedSignal.test.ts @@ -72,7 +72,7 @@ describe("SyncedSignal", () => { }); it("can get exponential ramp value in the future", async () => { - let sched; + let sched: SyncedSignal; const buffer = await Offline(({ transport }) => { sched = new SyncedSignal(0.5).toDestination(); sched.setValueAtTime(0.5, 0); @@ -89,7 +89,7 @@ describe("SyncedSignal", () => { }); it("can get exponential approach in the future", async () => { - let sched; + let sched: SyncedSignal; const buffer = await Offline(({ transport }) => { sched = new SyncedSignal(0.5).toDestination(); sched.setValueAtTime(0.5, 0); @@ -105,7 +105,7 @@ describe("SyncedSignal", () => { }); it("can loop the signal when the Transport loops", async () => { - let sched; + let sched: SyncedSignal; const buffer = await Offline(({ transport }) => { sched = new SyncedSignal(1).toDestination(); transport.setLoopPoints(0, 1); @@ -121,10 +121,10 @@ describe("SyncedSignal", () => { }); it("can get set a curve in the future", async () => { - let sched; + let sched: SyncedSignal; const buffer = await Offline(({ transport }) => { sched = new SyncedSignal(0).toDestination(); - sched.setValueCurveAtTime([0, 1, 0.2, 0.8, 0], 0, 1); + sched.setValueCurveAtTime([0, 1, 0.2, 0.8, 0], 0, 1, 1); transport.start(0.2); }, 1); buffer.forEach((sample, time) => { @@ -136,7 +136,7 @@ describe("SyncedSignal", () => { }); it("can scale a curve value", async () => { - let sched; + let sched: SyncedSignal; const buffer = await Offline(({ transport }) => { sched = new SyncedSignal(1).toDestination(); sched.setValueCurveAtTime([0, 1, 0], 0, 1, 0.5); @@ -148,7 +148,7 @@ describe("SyncedSignal", () => { }); it("can schedule a linear ramp between two times", async () => { - let sched; + let sched: SyncedSignal; const buffer = await Offline(({ transport }) => { sched = new SyncedSignal(0).toDestination(); sched.linearRampTo(1, 1, 1); @@ -162,7 +162,7 @@ describe("SyncedSignal", () => { }); it("can get exponential ramp value between two times", async () => { - let sched; + let sched: SyncedSignal; const buffer = await Offline(({ transport }) => { sched = new SyncedSignal(1).toDestination(); sched.exponentialRampTo(3, 1, 1); @@ -176,7 +176,7 @@ describe("SyncedSignal", () => { }); it("can cancel and hold a scheduled value", async () => { - let sched; + let sched: SyncedSignal; const buffer = await Offline(({ transport }) => { sched = new SyncedSignal(0).toDestination(); sched.setValueAtTime(0, 0); @@ -191,7 +191,7 @@ describe("SyncedSignal", () => { }); it("can cancel a scheduled value", async () => { - let sched; + let sched: SyncedSignal; const buffer = await Offline(({ transport }) => { sched = new SyncedSignal(0).toDestination(); sched.setValueAtTime(0, 0); @@ -207,7 +207,7 @@ describe("SyncedSignal", () => { }); it("can automate values with different units", async () => { - let sched; + let sched: SyncedSignal; const buffer = await Offline(({ transport }) => { sched = new SyncedSignal(-10, "decibels").toDestination(); sched.setValueAtTime(-5, 0); diff --git a/Tone/signal/SyncedSignal.ts b/Tone/signal/SyncedSignal.ts index df9471394..711a404cc 100644 --- a/Tone/signal/SyncedSignal.ts +++ b/Tone/signal/SyncedSignal.ts @@ -143,7 +143,7 @@ export class SyncedSignal< } setTargetAtTime( - value, + value: UnitMap[TypeName], startTime: TransportTime, timeConstant: number ): this { diff --git a/test/helper/Basic.ts b/test/helper/Basic.ts index 4a634985b..eaadbaf14 100644 --- a/test/helper/Basic.ts +++ b/test/helper/Basic.ts @@ -17,7 +17,7 @@ import { ConnectTest } from "./Connect.js"; export const testAudioContext = new OfflineContext(1, 1, 11025); -export function BasicTests(Constr, ...args: any[]): void { +export function BasicTests(Constr: any, ...args: any[]): void { context("Basic", () => { before(() => { return getContext().resume(); @@ -30,17 +30,23 @@ export function BasicTests(Constr, ...args: any[]): void { expect(instance.disposed).to.equal(true); // also check all of its attributes to see if they also have the right context for (const member in instance) { - if (instance[member] instanceof Tone && member !== "context") { + if ( + (instance as any)[member] instanceof Tone && + member !== "context" + ) { expect( - instance[member].disposed, + (instance as any)[member].disposed, `member ${member}` ).to.equal(true); } } // check that all callback functions are assigned to noOp for (const member in instance) { - if (isFunction(instance[member]) && member.startsWith("on")) { - expect(instance[member]).to.equal(noOp); + if ( + isFunction((instance as any)[member]) && + member.startsWith("on") + ) { + expect((instance as any)[member]).to.equal(noOp); } } }); @@ -64,9 +70,9 @@ export function BasicTests(Constr, ...args: any[]): void { expect(instance.context).to.equal(testAudioContext); // also check all of its attributes to see if they also have the right context for (const member in instance) { - if (instance[member] instanceof ToneWithContext) { + if ((instance as any)[member] instanceof ToneWithContext) { expect( - instance[member].context, + (instance as any)[member].context, `member: ${member}` ).to.equal(testAudioContext); } @@ -90,7 +96,7 @@ export function BasicTests(Constr, ...args: any[]): void { it("exports its class name", () => { // find the constructor for (const className in Classes) { - if (Classes[className] === Constr) { + if ((Classes as any)[className] === Constr) { const instance = new Constr(...args); expect(instance.toString()).to.equal(className); instance.dispose(); diff --git a/test/helper/CompareToFile.ts b/test/helper/CompareToFile.ts index a7e648982..be83e9791 100644 --- a/test/helper/CompareToFile.ts +++ b/test/helper/CompareToFile.ts @@ -38,7 +38,7 @@ async function getBuffersToCompare( * Compare the output of the callback to a pre-rendered file */ export async function CompareToFile( - callback, + callback: (context: Context) => Promise | void, url: string, threshold = 0.001, RENDER_NEW = false, diff --git a/test/helper/Connect.ts b/test/helper/Connect.ts index f7f6072b3..9fdcdd387 100644 --- a/test/helper/Connect.ts +++ b/test/helper/Connect.ts @@ -8,7 +8,7 @@ export function connectTo(): Gain { return new Gain(); } -export function ConnectTest(constr, ...args: any[]): void { +export function ConnectTest(constr: any, ...args: any[]): void { it("handles input and output connections", () => { const instance = new constr(...args); // test each of the input and outputs and connect diff --git a/test/helper/Dispose.ts b/test/helper/Dispose.ts index 47d4cebcc..0dff2c374 100644 --- a/test/helper/Dispose.ts +++ b/test/helper/Dispose.ts @@ -1,4 +1,4 @@ -export function isDisposed(instance): void { +export function isDisposed(instance: any): void { for (const prop in instance) { if (instance.hasOwnProperty(prop)) { const member = instance[prop]; diff --git a/test/helper/EffectTests.ts b/test/helper/EffectTests.ts index 8367c04eb..1ad900726 100644 --- a/test/helper/EffectTests.ts +++ b/test/helper/EffectTests.ts @@ -5,7 +5,7 @@ import { connectFrom, connectTo } from "./Connect.js"; import { Offline } from "./Offline.js"; import { PassAudio } from "./PassAudio.js"; -export function EffectTests(Constr, args?, before?): void { +export function EffectTests(Constr: any, args?: any, before?: any): void { context("Effect Tests", () => { it("has an input and output", () => { const instance = new Constr(args); diff --git a/test/helper/InstrumentTests.ts b/test/helper/InstrumentTests.ts index f959e3f3c..ac0067289 100644 --- a/test/helper/InstrumentTests.ts +++ b/test/helper/InstrumentTests.ts @@ -7,12 +7,12 @@ import { connectTo } from "./Connect.js"; import { Offline } from "./Offline.js"; import { OutputAudio } from "./OutputAudio.js"; -function wait(time) { +function wait(time: any) { return new Promise((done) => setTimeout(done, time)); } export function InstrumentTest( - Constr, + Constr: any, note?: Frequency, constrArg?: any, optionsIndex?: any, diff --git a/test/helper/MonophonicTests.ts b/test/helper/MonophonicTests.ts index e46a43595..7db262f90 100644 --- a/test/helper/MonophonicTests.ts +++ b/test/helper/MonophonicTests.ts @@ -2,7 +2,7 @@ import { expect } from "chai"; import { Offline } from "./Offline.js"; -export function MonophonicTest(Constr, note, constrArg?): void { +export function MonophonicTest(Constr: any, note: any, constrArg?: any): void { context("Monophonic Tests", () => { it("has an onsilence callback which is invoked after the release has finished", () => { let wasInvoked = false; diff --git a/test/helper/OscillatorTests.ts b/test/helper/OscillatorTests.ts index 486b4da5e..8361f680b 100644 --- a/test/helper/OscillatorTests.ts +++ b/test/helper/OscillatorTests.ts @@ -3,7 +3,7 @@ import { expect } from "chai"; import { connectFrom } from "./Connect.js"; import { Offline } from "./Offline.js"; -export function OscillatorTests(Constr, args?): void { +export function OscillatorTests(Constr: any, args?: any): void { context("Oscillator Tests", () => { it("can be created with an options object", () => { const instance = new Constr({ diff --git a/test/helper/OutputAudio.ts b/test/helper/OutputAudio.ts index 45ecc31f5..2f372a0f6 100644 --- a/test/helper/OutputAudio.ts +++ b/test/helper/OutputAudio.ts @@ -2,7 +2,7 @@ import { expect } from "chai"; import { Offline } from "./Offline.js"; -export function OutputAudio(callback): Promise { +export function OutputAudio(callback: any): Promise { return Offline(callback, 0.1).then((buffer) => { expect(buffer.isSilent(), "no audio").to.equal(false); }); diff --git a/test/helper/SourceTests.ts b/test/helper/SourceTests.ts index f3a9916df..e295bffd2 100644 --- a/test/helper/SourceTests.ts +++ b/test/helper/SourceTests.ts @@ -5,7 +5,7 @@ import { connectTo } from "./Connect.js"; import { Offline } from "./Offline.js"; import { OutputAudio } from "./OutputAudio.js"; -export function SourceTests(Constr, args?): void { +export function SourceTests(Constr: any, args?: any): void { context("Source Tests", () => { it("can connect the output", () => { const instance = new Constr(args); diff --git a/test/types.d.ts b/test/types.d.ts new file mode 100644 index 000000000..183516725 --- /dev/null +++ b/test/types.d.ts @@ -0,0 +1,5 @@ +declare module "array2d"; +declare module "plotly.js-dist"; +declare module "fft-windowing"; +declare module "fourier-transform"; +declare module "audiobuffer-to-wav"; diff --git a/tsconfig.json b/tsconfig.json index 1bad651ff..b86bd8fd3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,7 @@ "strictNullChecks": true, "target": "ES6", "module": "Node16", - "noImplicitAny": false, + "noImplicitAny": true, "importHelpers": true, "noUnusedLocals": false, "removeComments": false,