Skip to content

Commit

Permalink
Merge pull request #1193 from rvilarl/fix/ts-nocheck
Browse files Browse the repository at this point in the history
several `ts-nocheck` resolved
  • Loading branch information
0xfe authored Oct 30, 2021
2 parents 1e98874 + 242f1e0 commit 6e28ebb
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 109 deletions.
5 changes: 5 additions & 0 deletions src/beam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export class Beam extends Element {
private beam_count: number;
private unbeamable?: boolean;

/** Get the direction of the beam */
getStemDirection(): number {
return this.stem_direction;
}

/**
* Get the default beam groups for a provided time signature.
* Attempt to guess if the time signature is not found in table.
Expand Down
11 changes: 4 additions & 7 deletions src/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ export class Factory {
}

StaveTie(params: {
from: Note;
to: Note;
from: Note | null;
to: Note | null;
first_indices?: number[];
last_indices?: number[];
text?: string;
Expand Down Expand Up @@ -564,8 +564,8 @@ export class Factory {
}

VibratoBracket(params: {
from: Note;
to: Note;
from: Note | null;
to: Note | null;
options: {
harsh?: boolean;
line?: number;
Expand Down Expand Up @@ -612,9 +612,6 @@ export class Factory {
return textBracket;
}

// TODO: SystemOptions make all properties optional.
// eslint-disable-next-line
// @ts-ignore
System(params: SystemOptions = {}): System {
params.factory = this;
const system = new System(params).setContext(this.context);
Expand Down
8 changes: 4 additions & 4 deletions src/stavehairpin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { RenderContext } from './rendercontext';
import { RuntimeError } from './util';

export interface StaveHairpinRenderOptions {
right_shift_ticks: number;
left_shift_ticks: number;
right_shift_ticks?: number;
left_shift_ticks?: number;
left_shift_px: number;
right_shift_px: number;
height: number;
Expand Down Expand Up @@ -70,8 +70,8 @@ export class StaveHairpin extends Element {
throw new RuntimeError('BadArguments', 'A valid Formatter must be provide to draw offsets by ticks.');
}

const l_shift_px = ppt * options.left_shift_ticks;
const r_shift_px = ppt * options.right_shift_ticks;
const l_shift_px = ppt * (options.left_shift_ticks ?? 0);
const r_shift_px = ppt * (options.right_shift_ticks ?? 0);

const hairpin_options = {
height: options.height,
Expand Down
15 changes: 8 additions & 7 deletions src/stavetie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

import { Element } from './element';
import { Note } from './note';
import { Stave } from './stave';
import { FontInfo } from './types/common';
import { RuntimeError } from './util';

export interface TieNotes {
first_note: Note;
last_note: Note;
first_note: Note | null;
last_note: Note | null;
first_indices?: number[];
last_indices?: number[];
}
Expand Down Expand Up @@ -173,7 +174,7 @@ export class StaveTie extends Element {

ctx.save();
ctx.setFont(this.font.family, this.font.size, this.font.weight);
ctx.fillText(this.text, center_x + this.render_options.text_shift_x, stave.getYForTopText() - 1);
ctx.fillText(this.text, center_x + this.render_options.text_shift_x, (stave as Stave).getYForTopText() - 1);
ctx.restore();
}

Expand All @@ -194,9 +195,9 @@ export class StaveTie extends Element {
stem_direction = first_note.getStemDirection();
first_ys = first_note.getYs();
} else {
const stave = last_note.checkStave();
const stave = (last_note as Note).checkStave();
first_x_px = stave.getTieStartX();
first_ys = last_note.getYs();
first_ys = (last_note as Note).getYs();
this.notes.first_indices = this.notes.last_indices;
}

Expand All @@ -205,9 +206,9 @@ export class StaveTie extends Element {
stem_direction = last_note.getStemDirection();
last_ys = last_note.getYs();
} else {
const stave = first_note.checkStave();
const stave = (first_note as Note).checkStave();
last_x_px = stave.getTieEndX();
last_ys = first_note.getYs();
last_ys = (first_note as Note).getYs();
this.notes.last_indices = this.notes.first_indices;
}

Expand Down
6 changes: 3 additions & 3 deletions src/vibratobracket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ export class VibratoBracket extends Element {
* An undefined value for the start or stop note indicates that the vibrato
* is drawn from the beginning or until the end of the stave accordingly.
*/
constructor(bracket_data: { stop?: Note; start?: Note }) {
constructor(bracket_data: { stop?: Note | null; start?: Note | null }) {
super();

this.start = bracket_data.start;
this.stop = bracket_data.stop;
if (bracket_data.start) this.start = bracket_data.start;
if (bracket_data.stop) this.stop = bracket_data.stop;

this.line = 1;

Expand Down
29 changes: 13 additions & 16 deletions tests/auto_beam_formatting_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
//
// Auto Beaming Tests

/* eslint-disable */
// @ts-nocheck

// TODO: Beam has a "private readonly stem_direction" without an accessor.
// TODO: Beam.generateBeams(voice.getTickables() as StemmableNote[], ...) requires a cast to StemmableNote[].
// Is there a cleaner way to handle this?

import { VexFlowTests, TestOptions, concat } from './vexflow_test_helpers';
import { Beam } from 'beam';
import { EasyScore } from 'easyscore';
import { Fraction } from 'fraction';
import { Stem } from 'stem';
import { StemmableNote } from 'stemmablenote';
import { EasyScore } from 'easyscore';

import { concat, TestOptions, VexFlowTests } from './vexflow_test_helpers';

const AutoBeamFormattingTests = {
Start(): void {
Expand Down Expand Up @@ -114,12 +111,12 @@ function evenGroupStemDirections(options: TestOptions): void {

beams.forEach((beam) => beam.setContext(f.getContext()).draw());

equal(beams[0].stem_direction, Stem.UP);
equal(beams[1].stem_direction, Stem.UP);
equal(beams[2].stem_direction, Stem.UP);
equal(beams[3].stem_direction, Stem.UP);
equal(beams[4].stem_direction, Stem.DOWN);
equal(beams[5].stem_direction, Stem.DOWN);
equal(beams[0].getStemDirection(), Stem.UP);
equal(beams[1].getStemDirection(), Stem.UP);
equal(beams[2].getStemDirection(), Stem.UP);
equal(beams[3].getStemDirection(), Stem.UP);
equal(beams[4].getStemDirection(), Stem.DOWN);
equal(beams[5].getStemDirection(), Stem.DOWN);

ok(true, 'Auto Beaming Applicator Test');
}
Expand All @@ -136,10 +133,10 @@ function oddGroupStemDirections(options: TestOptions): void {
const groups = [new Fraction(3, 8)];
const beams = Beam.applyAndGetBeams(voice, undefined, groups);

equal(beams[0].stem_direction, Stem.DOWN, 'Notes are equidistant from middle line');
equal(beams[1].stem_direction, Stem.DOWN);
equal(beams[2].stem_direction, Stem.UP);
equal(beams[3].stem_direction, Stem.DOWN, 'Notes are equidistant from middle line');
equal(beams[0].getStemDirection(), Stem.DOWN, 'Notes are equidistant from middle line');
equal(beams[1].getStemDirection(), Stem.DOWN);
equal(beams[2].getStemDirection(), Stem.UP);
equal(beams[3].getStemDirection(), Stem.DOWN, 'Notes are equidistant from middle line');

f.Formatter().joinVoices([voice]).formatToStave([voice], stave);

Expand Down
39 changes: 18 additions & 21 deletions tests/beam_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
//
// Beam Tests

/* eslint-disable */
// @ts-nocheck

// TODO: Beam has a "private readonly stem_direction" without an accessor.
// TODO: Factory.Beam()'s 'notes' argument is a StemmableNote[], but we only have access to Tickable[].

import { VexFlowTests, TestOptions, concat } from './vexflow_test_helpers';
import { Beam } from 'beam';
import { StaveNoteStruct } from 'stavenote';
import { Stem } from 'stem';
import { Voice } from 'voice';
import { StemmableNote } from 'stemmablenote';
import { StaveNoteStruct } from 'stavenote';
import { TabNoteStruct } from 'tabnote';
import { Voice } from 'voice';

import { concat, TestOptions, VexFlowTests } from './vexflow_test_helpers';

const BeamTests = {
Start(): void {
Expand Down Expand Up @@ -208,12 +205,12 @@ function autoStem(options: TestOptions): void {
const UP = Stem.UP;
const DOWN = Stem.DOWN;

equal(beams[0].stem_direction, UP);
equal(beams[1].stem_direction, UP);
equal(beams[2].stem_direction, UP);
equal(beams[3].stem_direction, UP);
equal(beams[4].stem_direction, DOWN);
equal(beams[5].stem_direction, DOWN);
equal(beams[0].getStemDirection(), UP);
equal(beams[1].getStemDirection(), UP);
equal(beams[2].getStemDirection(), UP);
equal(beams[3].getStemDirection(), UP);
equal(beams[4].getStemDirection(), DOWN);
equal(beams[5].getStemDirection(), DOWN);

f.draw();

Expand All @@ -237,13 +234,13 @@ function mixed(options: TestOptions): void {
[0, 4],
[4, 8],
[8, 12],
].forEach((range) => f.Beam({ notes: voice1.getTickables().slice(range[0], range[1]) }));
].forEach((range) => f.Beam({ notes: voice1.getTickables().slice(range[0], range[1]) as StemmableNote[] }));

[
[0, 4],
[4, 8],
[8, 12],
].forEach((range) => f.Beam({ notes: voice2.getTickables().slice(range[0], range[1]) }));
].forEach((range) => f.Beam({ notes: voice2.getTickables().slice(range[0], range[1]) as StemmableNote[] }));

f.Formatter().joinVoices([voice1, voice2]).formatToStave([voice1, voice2], stave);

Expand Down Expand Up @@ -271,8 +268,8 @@ function mixed2(options: TestOptions): void {
{ time: '31/64' }
);

f.Beam({ notes: voice.getTickables().slice(0, 12) });
f.Beam({ notes: voice2.getTickables().slice(0, 12) });
f.Beam({ notes: voice.getTickables().slice(0, 12) as StemmableNote[] });
f.Beam({ notes: voice2.getTickables().slice(0, 12) as StemmableNote[] });

f.Formatter().joinVoices([voice, voice2]).formatToStave([voice, voice2], stave);

Expand Down Expand Up @@ -315,7 +312,7 @@ function partial(options: TestOptions): void {
{ time: '89/64' }
);

const notes = voice.getTickables();
const notes = voice.getTickables() as StemmableNote[];
f.Beam({ notes: notes.slice(0, 3) });
f.Beam({ notes: notes.slice(3, 9) });
f.Beam({ notes: notes.slice(9, 13) });
Expand All @@ -335,7 +332,7 @@ function tradeoffs(options: TestOptions): void {

const voice = score.voice(score.notes('a4/8, b4/8, c4/8, d4/8, g4/8, a4/8, b4/8, c4/8', { stem: 'up' }));

const notes = voice.getTickables();
const notes = voice.getTickables() as StemmableNote[];
f.Beam({ notes: notes.slice(0, 4) });
f.Beam({ notes: notes.slice(4, 8) });

Expand All @@ -355,7 +352,7 @@ function insane(options: TestOptions): void {
score.notes('g4/8, g5/8, c4/8, b5/8, g4/8[stem="down"], a5[stem="down"], b4[stem="down"], c4/8', { stem: 'up' })
);

const notes = voice.getTickables();
const notes = voice.getTickables() as StemmableNote[];
f.Beam({ notes: notes.slice(0, 4) });
f.Beam({ notes: notes.slice(4, 7) });

Expand Down Expand Up @@ -394,7 +391,7 @@ function outlier(options: TestOptions): void {
)
);

const notes = voice.getTickables();
const notes = voice.getTickables() as StemmableNote[];
f.Beam({ notes: notes.slice(0, 4) });
f.Beam({ notes: notes.slice(4, 8) });

Expand Down
13 changes: 6 additions & 7 deletions tests/pedalmarking_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
//
// PedalMarking Tests

/* eslint-disable */
// @ts-nocheck

// TODO: Fix Error => Type 'Tickable' is not assignable to type 'StaveNote'.

import { Factory } from 'factory';
import { StaveNote } from 'stavenote';
import { Tickable } from 'tickable';

import { TestOptions, VexFlowTests } from './vexflow_test_helpers';

const PedalMarkingTests = {
Expand Down Expand Up @@ -54,15 +53,15 @@ function createTest(makePedal: (f: Factory, v1: Tickable[], v2: Tickable[]) => v
function withSimplePedal(style: string) {
return (factory: Factory, notes0: Tickable[], notes1: Tickable[]) =>
factory.PedalMarking({
notes: [notes0[0], notes0[2], notes0[3], notes1[3]],
notes: [notes0[0], notes0[2], notes0[3], notes1[3]] as StaveNote[],
options: { style },
});
}

function withReleaseAndDepressedPedal(style: string) {
return (factory: Factory, notes0: Tickable[], notes1: Tickable[]) =>
factory.PedalMarking({
notes: [notes0[0], notes0[3], notes0[3], notes1[1], notes1[1], notes1[3]],
notes: [notes0[0], notes0[3], notes0[3], notes1[1], notes1[1], notes1[3]] as StaveNote[],
options: { style },
});
}
Expand All @@ -75,7 +74,7 @@ const releaseDepress2 = createTest(withReleaseAndDepressedPedal('mixed'));

const customTest1 = createTest((factory, notes0, notes1) => {
const pedal = factory.PedalMarking({
notes: [notes0[0], notes1[3]],
notes: [notes0[0], notes1[3]] as StaveNote[],
options: { style: 'text' },
});
pedal.setCustomText('una corda', 'tre corda');
Expand All @@ -84,7 +83,7 @@ const customTest1 = createTest((factory, notes0, notes1) => {

const customTest2 = createTest((factory, notes0, notes1) => {
const pedal = factory.PedalMarking({
notes: [notes0[0], notes1[3]],
notes: [notes0[0], notes1[3]] as StaveNote[],
options: { style: 'mixed' },
});
pedal.setCustomText('Sost. Ped.');
Expand Down
Loading

0 comments on commit 6e28ebb

Please sign in to comment.