diff --git a/editor/Change.ts b/editor/Change.ts index 44edbf9d..096947d4 100644 --- a/editor/Change.ts +++ b/editor/Change.ts @@ -88,13 +88,13 @@ export class ChangeSequence extends UndoableChange { this._didSomething(); } - protected _doForwards(): void { + protected override _doForwards(): void { for (let i: number = 0; i < this._changes.length; i++) { this._changes[i].redo(); } } - protected _doBackwards(): void { + protected override _doBackwards(): void { for (let i: number = this._changes.length-1; i >= 0 ; i--) { this._changes[i].undo(); } diff --git a/editor/EasyPointers.ts b/editor/EasyPointers.ts index 2ddb544a..b397e272 100644 --- a/editor/EasyPointers.ts +++ b/editor/EasyPointers.ts @@ -1485,13 +1485,13 @@ export function getElementDimensions(element: HTMLElement, elementBox: `${Elemen switch (elementBox) { case ElementBox.borderBox: { return {width: element.offsetWidth, height: element.offsetHeight}; - } break; + } case ElementBox.insideBorder: { return { width: element.offsetWidth - parseFloat(styles.borderLeft) - parseFloat(styles.borderRight), height: element.offsetHeight - parseFloat(styles.borderTop) - parseFloat(styles.borderBottom), }; - } break; + } case ElementBox.paddingBox: { if (styles.display == "inline") { // For inline elements, the reported scrollWidth and scrollHeight are always zero even if there's a border. @@ -1502,7 +1502,7 @@ export function getElementDimensions(element: HTMLElement, elementBox: `${Elemen } else { return {width: element.scrollWidth, height: element.scrollHeight}; } - } break; + } case ElementBox.contentBox: { if (styles.display == "inline") { return { @@ -1515,7 +1515,7 @@ export function getElementDimensions(element: HTMLElement, elementBox: `${Elemen height: element.scrollHeight - parseFloat(styles.paddingTop) - parseFloat(styles.paddingBottom), }; } - } break; + } case ElementBox.imagePixels: { if (element instanceof HTMLImageElement) { return {width: element.naturalWidth, height: element.naturalHeight}; @@ -1524,10 +1524,10 @@ export function getElementDimensions(element: HTMLElement, elementBox: `${Elemen } else { throw new Error("EasyPointers: Unsupported element type for image box: " + element.tagName); } - } break; + } case ElementBox.svgTransform: { throw new Error("EasyPointers: svgTransform unsupported for HTML elements."); - }// break; // unreachable code because of the throw. + } default: throw new Error("EasyPointers: Unrecognized element box: " + elementBox); } } diff --git a/editor/MidiInput.ts b/editor/MidiInput.ts index 7f1b1513..6de0475b 100644 --- a/editor/MidiInput.ts +++ b/editor/MidiInput.ts @@ -6,20 +6,19 @@ import {AnalogousDrum, analogousDrumMap, MidiEventType} from "./Midi.js"; declare global { interface Navigator { - requestMIDIAccess?(): Promise; + // Defined in latest TypeScript typings + // requestMIDIAccess?(): Promise; } } +// Maybe these can be moved to standard lib typings as well, will have to look into it further. + interface MIDIInput extends EventTarget { id: string; type: "input" | "output"; state: "disconnected" | "connected"; } -interface MIDIConnectionEvent { - port: MIDIInput; -} - interface MIDIMessageEvent { data: [type: number, key: number, velocity: number]; target: MIDIInput; @@ -61,6 +60,7 @@ export class MidiInputHandler { } private _handleStateChange = (event: MIDIConnectionEvent) => { + if (!event.port) return; if (event.port.type !== "input") return; switch (event.port.state) { diff --git a/editor/PatternEditor.ts b/editor/PatternEditor.ts index af521727..987fe0d9 100644 --- a/editor/PatternEditor.ts +++ b/editor/PatternEditor.ts @@ -178,7 +178,7 @@ export class PatternEditor { / minDivision) * minDivision; if (this._pattern != null) { - const cursorPartForMatching: Number = Math.max(0, Math.min(partsPerPattern - 1, this._cursor.exactPart)); + const cursorPartForMatching: number = Math.max(0, Math.min(partsPerPattern - 1, this._cursor.exactPart)); for (const note of this._pattern.notes) { if (note.end <= cursorPartForMatching) { this._cursor.prevNote = note; diff --git a/editor/changes.ts b/editor/changes.ts index 87f390c9..0944a1f1 100644 --- a/editor/changes.ts +++ b/editor/changes.ts @@ -352,7 +352,7 @@ class ChangePins extends UndoableChange { this._didSomething(); } - protected _doForwards(): void { + protected override _doForwards(): void { this._note.pins = this._newPins; this._note.pitches = this._newPitches; this._note.start = this._newStart; @@ -361,7 +361,7 @@ class ChangePins extends UndoableChange { if (this._doc != null) this._doc.notifier.changed(); } - protected _doBackwards(): void { + protected override _doBackwards(): void { this._note.pins = this._oldPins; this._note.pitches = this._oldPitches; this._note.start = this._oldStart; @@ -1304,7 +1304,7 @@ class ChangeInstrumentSlider extends Change { this._instrument = this._doc.song.channels[this._doc.channel].instruments[this._doc.getCurrentInstrument()]; } - public commit(): void { + public override commit(): void { if (!this.isNoop()) { this._instrument.preset = this._instrument.type; this._doc.notifier.changed(); @@ -1470,7 +1470,7 @@ export class ChangeFilterAddPoint extends UndoableChange { this.redo(); } - protected _doForwards(): void { + protected override _doForwards(): void { this._filterSettings.controlPoints.splice(this._index, 0, this._point); this._filterSettings.controlPointCount++; this._filterSettings.controlPoints.length = this._filterSettings.controlPointCount; @@ -1482,7 +1482,7 @@ export class ChangeFilterAddPoint extends UndoableChange { this._doc.notifier.changed(); } - protected _doBackwards(): void { + protected override _doBackwards(): void { this._filterSettings.controlPoints.splice(this._index, 1); this._filterSettings.controlPointCount--; this._filterSettings.controlPoints.length = this._filterSettings.controlPointCount; @@ -1520,14 +1520,14 @@ export class ChangeFilterMovePoint extends UndoableChange { this.redo(); } - protected _doForwards(): void { + protected override _doForwards(): void { this._point.freq = this._newFreq; this._point.gain = this._newGain; this._instrument.preset = this._instrumentNextPreset; this._doc.notifier.changed(); } - protected _doBackwards(): void { + protected override _doBackwards(): void { this._point.freq = this._oldFreq; this._point.gain = this._oldGain; this._instrument.preset = this._instrumentPrevPreset; @@ -1558,14 +1558,14 @@ export class ChangeFadeInOut extends UndoableChange { this.redo(); } - protected _doForwards(): void { + protected override _doForwards(): void { this._instrument.fadeIn = this._newFadeIn; this._instrument.fadeOut = this._newFadeOut; this._instrument.preset = this._instrumentNextPreset; this._doc.notifier.changed(); } - protected _doBackwards(): void { + protected override _doBackwards(): void { this._instrument.fadeIn = this._oldFadeIn; this._instrument.fadeOut = this._oldFadeOut; this._instrument.preset = this._instrumentPrevPreset; @@ -1761,12 +1761,12 @@ export class ChangePitchAdded extends UndoableChange { this.redo(); } - protected _doForwards(): void { + protected override _doForwards(): void { this._note.pitches.splice(this._index, 0, this._pitch); this._doc.notifier.changed(); } - protected _doBackwards(): void { + protected override _doBackwards(): void { this._note.pitches.splice(this._index, 1); this._doc.notifier.changed(); } @@ -1946,7 +1946,7 @@ export class ChangeEnsurePatternExists extends UndoableChange { this._doForwards(); } - protected _doForwards(): void { + protected override _doForwards(): void { const song: Song = this._doc.song; for (let j: number = song.patternsPerChannel; j < this._newPatternCount; j++) { for (let i: number = 0; i < song.getChannelCount(); i++) { @@ -1962,7 +1962,7 @@ export class ChangeEnsurePatternExists extends UndoableChange { this._doc.notifier.changed(); } - protected _doBackwards(): void { + protected override _doBackwards(): void { const song: Song = this._doc.song; const pattern: Pattern = song.channels[this._channelIndex].patterns[this._patternIndex - 1]; if (this._patternOldNotes != null) pattern.notes = this._patternOldNotes; @@ -2597,12 +2597,12 @@ export class ChangeNoteAdded extends UndoableChange { this.redo(); } - protected _doForwards(): void { + protected override _doForwards(): void { this._pattern.notes.splice(this._index, 0, this._note); this._doc.notifier.changed(); } - protected _doBackwards(): void { + protected override _doBackwards(): void { this._pattern.notes.splice(this._index, 1); this._doc.notifier.changed(); } @@ -2831,13 +2831,13 @@ class ChangeTransposeNote extends UndoableChange { this._didSomething(); } - protected _doForwards(): void { + protected override _doForwards(): void { this._note.pins = this._newPins; this._note.pitches = this._newPitches; this._doc.notifier.changed(); } - protected _doBackwards(): void { + protected override _doBackwards(): void { this._note.pins = this._oldPins; this._note.pitches = this._oldPitches; this._doc.notifier.changed(); @@ -2893,14 +2893,14 @@ export class ChangePatternSelection extends UndoableChange { this._didSomething(); } - protected _doForwards(): void { + protected override _doForwards(): void { this._doc.selection.patternSelectionStart = this._newStart; this._doc.selection.patternSelectionEnd = this._newEnd; this._doc.selection.patternSelectionActive = this._newActive; this._doc.notifier.changed(); } - protected _doBackwards(): void { + protected override _doBackwards(): void { this._doc.selection.patternSelectionStart = this._oldStart; this._doc.selection.patternSelectionEnd = this._oldEnd; this._doc.selection.patternSelectionActive = this._oldActive; @@ -3131,12 +3131,12 @@ export class ChangeSizeBend extends UndoableChange { this._didSomething(); } - protected _doForwards(): void { + protected override _doForwards(): void { this._note.pins = this._newPins; this._doc.notifier.changed(); } - protected _doBackwards(): void { + protected override _doBackwards(): void { this._note.pins = this._oldPins; this._doc.notifier.changed(); } diff --git a/editor/index.ts b/editor/index.ts index 0ce42ee4..39505fdd 100644 --- a/editor/index.ts +++ b/editor/index.ts @@ -1,11 +1,11 @@ // Copyright (c) John Nesky and contributing authors, distributed under the MIT license, see accompanying the LICENSE.md file. -export {Dictionary, DictionaryArray, EnvelopeType, InstrumentType, Transition, Chord, Envelope, Config} from "../synth/SynthConfig.js"; +export {type Dictionary, type DictionaryArray, EnvelopeType, InstrumentType, type Transition, type Chord, type Envelope, Config} from "../synth/SynthConfig.js"; export {EditorConfig} from "./EditorConfig.js"; export {ColorConfig} from "./ColorConfig.js"; import "./style.js"; // Import for the side effects, there's no exports. export {SongEditor} from "./SongEditor.js"; -export {NotePin, Note, Pattern, Instrument, Channel, Song, Synth} from "../synth/synth.js"; +export {type NotePin, Note, Pattern, Instrument, Channel, Song, Synth} from "../synth/synth.js"; export {SongDocument} from "./SongDocument.js"; export {ExportPrompt} from "./ExportPrompt.js"; export {ChangePreset} from "./changes.js"; diff --git a/player/index.ts b/player/index.ts index 1ad26ea7..d89f7438 100644 --- a/player/index.ts +++ b/player/index.ts @@ -588,4 +588,4 @@ renderZoomIcon(); renderPlayButton(); // When compiling synth.ts as a standalone module named "beepbox", expose these classes as members to JavaScript: -export {Dictionary, DictionaryArray, EnvelopeType, InstrumentType, Transition, Chord, Envelope, Config, NotePin, Note, Pattern, Instrument, Channel, Synth}; +export {type Dictionary, type DictionaryArray, EnvelopeType, InstrumentType, type Transition, type Chord, type Envelope, Config, type NotePin, Note, Pattern, Instrument, Channel, Synth}; diff --git a/synth/synth.ts b/synth/synth.ts index 163f2cc2..4ae59321 100644 --- a/synth/synth.ts +++ b/synth/synth.ts @@ -3240,7 +3240,7 @@ export class Song { } break; default: { throw new Error("Unrecognized song tag code " + String.fromCharCode(command) + " at index " + (charIndex - 1)); - } break; + } } } @@ -7801,14 +7801,14 @@ export class Synth { // When compiling synth.ts as a standalone module named "beepbox", expose these imported classes as members to JavaScript: export { - Dictionary, - DictionaryArray, + type Dictionary, + type DictionaryArray, FilterType, EnvelopeType, InstrumentType, - Transition, - Chord, - Envelope, + type Transition, + type Chord, + type Envelope, Config, fastFourierTransform, forwardRealFourierTransform, diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..68bc09d8 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "module": "NodeNext", + "target": "ESNext", + "isolatedModules": true, + "noEmit": true, + "skipLibCheck": true, // temp + "strict": true, + "strictPropertyInitialization": false, // temp + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + // "noUncheckedIndexedAccess": true, // needs oversight to enable + "allowUnreachableCode": false, + "noUnusedLocals": true, + "allowUnusedLabels": false, + // "noUnusedParameters": true // needs oversight to enable + } +}