Skip to content

Commit 2ba4404

Browse files
committed
Fix tests
1 parent 324f8de commit 2ba4404

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

packages/cursorless-engine/src/DefaultSpokenFormMap.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { mapValues } from "lodash";
22
import {
3+
PartialSpokenFormTypes,
34
SpokenFormMap,
45
SpokenFormMapEntry,
56
SpokenFormMapKeyTypes,
@@ -154,9 +155,11 @@ export interface DefaultSpokenFormMapEntry {
154155
}
155156

156157
export type DefaultSpokenFormMap = {
157-
readonly [K in keyof SpokenFormMapKeyTypes]: Readonly<
158-
Record<SpokenFormMapKeyTypes[K], DefaultSpokenFormMapEntry>
159-
>;
158+
readonly [K in keyof SpokenFormMapKeyTypes]: K extends PartialSpokenFormTypes
159+
? Readonly<
160+
Partial<Record<SpokenFormMapKeyTypes[K], DefaultSpokenFormMapEntry>>
161+
>
162+
: Record<SpokenFormMapKeyTypes[K], DefaultSpokenFormMapEntry>;
160163
};
161164

162165
// FIXME: Don't cast here; need to make our own mapValues with stronger typing

packages/cursorless-engine/src/SpokenFormMap.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ export interface SpokenFormMapKeyTypes {
5858

5959
export type SpokenFormType = keyof SpokenFormMapKeyTypes;
6060

61+
/**
62+
* These are the types of spoken forms that are not total mappings, eg if you
63+
* look up a string in `spokenFormMap.customRegex`, you might get `undefined`,
64+
* even though technically the identifier type is `string`.
65+
*/
66+
export type PartialSpokenFormTypes = "customRegex";
67+
6168
export interface SpokenFormMapEntry {
6269
/**
6370
* The spoken forms for this entry. These could either be a user's custom
@@ -102,7 +109,7 @@ export interface SpokenFormMapEntry {
102109
* the value is a map of identifiers to {@link SpokenFormMapEntry}s.
103110
*/
104111
export type SpokenFormMap = {
105-
readonly [K in keyof SpokenFormMapKeyTypes]: Readonly<
106-
Record<SpokenFormMapKeyTypes[K], SpokenFormMapEntry>
107-
>;
112+
readonly [K in keyof SpokenFormMapKeyTypes]: K extends PartialSpokenFormTypes
113+
? Readonly<Partial<Record<SpokenFormMapKeyTypes[K], SpokenFormMapEntry>>>
114+
: Readonly<Record<SpokenFormMapKeyTypes[K], SpokenFormMapEntry>>;
108115
};

packages/cursorless-engine/src/generateSpokenForm/GeneratorSpokenFormMap.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {
2+
PartialSpokenFormMapKeys,
23
SpokenFormMap,
34
SpokenFormMapEntry,
45
SpokenFormMapKeyTypes,
56
SpokenFormType,
67
} from "../SpokenFormMap";
78

89
export type GeneratorSpokenFormMap = {
9-
readonly [K in keyof SpokenFormMapKeyTypes]: Record<
10-
SpokenFormMapKeyTypes[K],
11-
SingleTermSpokenForm
12-
>;
10+
readonly [K in keyof SpokenFormMapKeyTypes]: K extends PartialSpokenFormMapKeys
11+
? Partial<Record<SpokenFormMapKeyTypes[K], SingleTermSpokenForm>>
12+
: Record<SpokenFormMapKeyTypes[K], SingleTermSpokenForm>;
1313
};
1414

1515
export interface SingleTermSpokenForm {

packages/cursorless-engine/src/generateSpokenForm/primitiveTargetToSpokenForm.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,14 @@ export class PrimitiveTargetSpokenFormGenerator {
229229
case "customRegex":
230230
return (
231231
this.spokenFormMap.customRegex[scopeType.regex] ?? {
232-
type: "singleTerm",
233-
spokenForms: [],
232+
type: "customizable",
233+
spokenForms: {
234+
spokenForms: [],
235+
isCustom: true,
236+
defaultSpokenForms: [],
237+
requiresTalonUpdate: false,
238+
isPrivate: false,
239+
},
234240
spokenFormType: "customRegex",
235241
id: scopeType.regex,
236242
}

0 commit comments

Comments
 (0)