Skip to content

Commit 89d72fb

Browse files
Fix more types
1 parent 03e3bbd commit 89d72fb

8 files changed

Lines changed: 102 additions & 62 deletions

File tree

app/components/color-picker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export default class ColorPickerComponent extends Component<ColorPickerSignature
133133

134134
set(this._selectedColor, 'name', namedColor.name);
135135

136-
this.colorPicker?.setColors([this._selectedColor].mapBy('hex'));
136+
this.colorPicker?.setColors([this._selectedColor].map((c) => c.hex));
137137
}
138138

139139
/**

app/components/kuler.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import type { IpcRenderer } from 'electron';
1313
import { debounce } from 'throttle-debounce';
1414

1515
import 'swach/components/kuler-palette-row';
16+
import type ColorModel from 'swach/data-models/color';
1617
import type { ColorPOJO } from 'swach/services/color-utils';
1718
import type ColorUtils from 'swach/services/color-utils';
1819

1920
type harmonyTypes = 'analogous' | 'monochromatic' | 'tetrad' | 'triad';
2021

2122
class Palette {
22-
@tracked colors = [];
23+
@tracked colors: ColorModel[] = [];
2324
@tracked selectedColorIndex = 0;
2425

2526
createdAt: Date;
@@ -39,9 +40,7 @@ class Palette {
3940
interface KulerSignature {
4041
Element: HTMLDivElement;
4142
Args: {
42-
// TODO: correctly type this instead of using `any`
43-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
44-
baseColor: any;
43+
baseColor: ColorModel;
4544
};
4645
}
4746

@@ -53,10 +52,10 @@ export default class KulerComponent extends Component<KulerSignature> {
5352
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5453
_debouncedColorChange!: any;
5554
colorPicker!: iro.ColorPicker;
56-
harmonies = ['analogous', 'monochromatic', 'tetrad', 'triad'];
55+
harmonies = ['analogous', 'monochromatic', 'tetrad', 'triad'] as const;
5756
declare ipcRenderer: IpcRenderer;
5857

59-
@tracked baseColor;
58+
@tracked baseColor!: ColorModel;
6059
@tracked colors = [];
6160
@tracked palettes: Palette[] = [];
6261
@tracked selectedPalette!: Palette;
@@ -118,21 +117,22 @@ export default class KulerComponent extends Component<KulerSignature> {
118117
for (const harmony of this.harmonies) {
119118
const palette = new Palette(harmony as harmonyTypes);
120119

121-
//@ts-expect-error TODO fix this error later
122-
let colors = new TinyColor(this.baseColor.hex)[harmony](5);
120+
const tinyColors = new TinyColor(this.baseColor.hex)[harmony](5);
123121

124-
colors = colors.map((color: TinyColor) => {
122+
const colorPOJOs = tinyColors.map((color: TinyColor) => {
125123
return this.colorUtils.createColorPOJO(color.toHexString());
126124
});
127-
colors = colors.map((color: ColorPOJO) => color.attributes);
125+
const colors = colorPOJOs.map(
126+
(color: ColorPOJO) => color.attributes,
127+
) as unknown as ColorModel[];
128128

129129
palette.colors = colors;
130-
palettes.pushObject(palette);
130+
palettes.push(palette);
131131
}
132132

133133
this.palettes = palettes;
134134

135-
this.selectedPalette = this.palettes[selectedPaletteTypeIndex];
135+
this.selectedPalette = this.palettes[selectedPaletteTypeIndex] as Palette;
136136
}
137137

138138
@action
@@ -144,7 +144,7 @@ export default class KulerComponent extends Component<KulerSignature> {
144144
this.palettes.indexOf(this.selectedPalette),
145145
).then(() => {
146146
this.colorPicker.setColors(
147-
this.selectedPalette.colors.mapBy('hex'),
147+
this.selectedPalette.colors.map((color: ColorModel) => color.hex),
148148
this.selectedPalette.selectedColorIndex,
149149
);
150150
});
@@ -170,7 +170,7 @@ export default class KulerComponent extends Component<KulerSignature> {
170170
if (palette) {
171171
this.selectedPalette = palette;
172172
this.colorPicker.setColors(
173-
this.selectedPalette.colors.mapBy('hex'),
173+
this.selectedPalette.colors.map((color: ColorModel) => color.hex),
174174
palette.selectedColorIndex,
175175
);
176176
}
@@ -200,7 +200,7 @@ export default class KulerComponent extends Component<KulerSignature> {
200200
}
201201

202202
this.colorPicker.setColors(
203-
this.selectedPalette.colors.mapBy('hex'),
203+
this.selectedPalette.colors.map((color: ColorModel) => color.hex),
204204
this.selectedPalette.selectedColorIndex,
205205
);
206206
}
@@ -219,7 +219,7 @@ export default class KulerComponent extends Component<KulerSignature> {
219219
this.colorPicker = (iro.ColorPicker as any)(
220220
'#kuler-color-picker-container',
221221
{
222-
colors: this.selectedPalette.colors.mapBy('hex'),
222+
colors: this.selectedPalette.colors.map((color: ColorModel) => color.hex),
223223
layoutDirection: 'horizontal',
224224
layout: [
225225
{

app/controllers/application.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default class ApplicationController extends Controller {
3535
@tracked colorPickerColor?: ColorModel;
3636
@tracked colorPickerIsShown = false;
3737

38-
get hasLoggedInBeforeAndIsAuthenticated(): boolean {
38+
get hasLoggedInBeforeAndIsAuthenticated() {
3939
// eslint-disable-next-line ember/no-get
4040
const userHasLoggedInBefore = get(this.settings, 'userHasLoggedInBefore');
4141

@@ -45,27 +45,27 @@ export default class ApplicationController extends Controller {
4545
);
4646
}
4747

48-
get isContrastRoute(): boolean {
48+
get isContrastRoute() {
4949
return this.router.currentRouteName === 'contrast';
5050
}
5151

52-
get isKulerRoute(): boolean {
52+
get isKulerRoute() {
5353
return this.router.currentRouteName === 'kuler';
5454
}
5555

56-
get isPalettesRoute(): boolean {
56+
get isPalettesRoute() {
5757
return this.router.currentRouteName === 'palettes';
5858
}
5959

60-
get isSettingsRoute(): boolean {
60+
get isSettingsRoute() {
6161
return this.router.currentRouteName === 'settings';
6262
}
6363

64-
get isWelcomeRoute(): boolean {
65-
return this.router.currentRouteName.includes('welcome');
64+
get isWelcomeRoute() {
65+
return this.router.currentRouteName?.includes('welcome');
6666
}
6767

68-
get showColorWheel(): boolean {
68+
get showColorWheel() {
6969
return (
7070
this.hasLoggedInBeforeAndIsAuthenticated &&
7171
!this.isContrastRoute &&
@@ -74,7 +74,7 @@ export default class ApplicationController extends Controller {
7474
);
7575
}
7676

77-
get showEyedropperIcon(): boolean {
77+
get showEyedropperIcon() {
7878
return (
7979
this.hasLoggedInBeforeAndIsAuthenticated &&
8080
!this.isContrastRoute &&

app/controllers/kuler.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import Controller from '@ember/controller';
22
import { action } from '@ember/object';
33

4+
import type ColorModel from 'swach/data-models/color';
5+
46
export default class KulerController extends Controller {
57
queryParams = ['colorId'];
68

79
colorId = null;
10+
declare model: ColorModel;
811

912
@action
1013
goBack(): void {

app/data-sources/backup.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,26 @@ import { IndexedDBSource } from '@orbit/indexeddb';
44
import type {
55
InitializedRecord,
66
RecordIdentity,
7+
Record,
78
RecordSchema,
89
} from '@orbit/records';
910
import { clone } from '@orbit/utils';
1011

12+
import type ColorModel from 'swach/data-models/color';
13+
import type PaletteModel from 'swach/data-models/palette';
14+
15+
type PalettePOJO = Omit<Record, 'type'> & {
16+
type: 'palette';
17+
relationships: {
18+
colors: {
19+
data: RecordIdentity[];
20+
};
21+
};
22+
attributes: {
23+
colorOrder: RecordIdentity[];
24+
};
25+
};
26+
1127
import ENV from 'swach/config/environment';
1228
import type { ColorPOJO } from 'swach/services/color-utils';
1329

@@ -51,7 +67,7 @@ export default {
5167
delete color.relationships['palettes'];
5268

5369
if (paletteIdentities?.length) {
54-
color.relationships.palette = { data: paletteIdentities[0] };
70+
color.relationships['palette'] = { data: paletteIdentities[0] };
5571
newColors.push(color);
5672

5773
// We start at i = 1 because we can keep the original color in a single palette.
@@ -64,28 +80,29 @@ export default {
6480
newColors.push(colorCopy);
6581

6682
const palette = palettes.find(
67-
(record) => record.id === paletteIdentity.id,
83+
(record): record is PalettePOJO =>
84+
record.id === paletteIdentity?.id && record.type === 'palette',
6885
);
6986

7087
if (palette) {
71-
const replaceColorIdWithCopy = (c: ColorPOJO) => {
88+
const replaceColorIdWithCopy = (c: RecordIdentity) => {
7289
return c.id !== color.id
7390
? c
7491
: { type: 'color', id: colorCopy.id };
7592
};
7693

77-
if (palette.relationships?.['colors']?.data) {
94+
if (palette.relationships?.colors?.data) {
7895
// Replace color in palette with color copy
79-
palette.relationships['colors'].data =
80-
palette.relationships['colors'].data.map(
81-
replaceColorIdWithCopy,
82-
);
96+
palette.relationships.colors.data = palette.relationships.colors.data.map(
97+
replaceColorIdWithCopy,
98+
);
8399
}
84100

85101
if (palette.attributes?.['colorOrder']) {
86102
// Replace color id in colorOrder
87-
palette.attributes['colorOrder'] =
88-
palette.attributes['colorOrder'].map(replaceColorIdWithCopy);
103+
palette.attributes['colorOrder'] = palette.attributes[
104+
'colorOrder'
105+
].map(replaceColorIdWithCopy);
89106
}
90107
}
91108
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@
6969
"@release-it-plugins/workspaces": "^4.2.0",
7070
"@sentry/ember": "^7.120.1",
7171
"@tailwindcss/forms": "^0.5.9",
72-
"@tsconfig/ember": "^3.0.10",
7372
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
73+
"@tsconfig/ember": "^3.0.10",
7474
"@types/ember": "^4.0.11",
7575
"@types/eslint__js": "^8.42.3",
76+
"@types/node": "^22.15.28",
7677
"@types/qunit": "^2.19.12",
7778
"@types/sinon": "^17.0.3",
7879
"aws4fetch": "^1.0.20",

0 commit comments

Comments
 (0)