Skip to content

Commit 7bf5704

Browse files
authored
fix: type-check defaultLanguageOptions against LangOptions (#420)
1 parent b281abb commit 7bf5704

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

packages/core/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ export interface Language<
11751175
/**
11761176
* Default language options. User-defined options are merged with this object.
11771177
*/
1178-
defaultLanguageOptions?: LanguageOptions;
1178+
defaultLanguageOptions?: Options["LangOptions"];
11791179

11801180
/**
11811181
* Validates languageOptions for this language.

packages/core/tests/types/types.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,55 @@ const testLanguage: Language = {
210210

211211
testLanguage.defaultLanguageOptions satisfies LanguageOptions | undefined;
212212

213+
const testLanguage2: Language<{
214+
LangOptions: {
215+
howMuch: boolean;
216+
howMany: number;
217+
};
218+
Code: TestSourceCode;
219+
RootNode: TestRootNode;
220+
Node: TestNode;
221+
}> = {
222+
fileType: "text",
223+
lineStart: 1,
224+
columnStart: 1,
225+
nodeTypeKey: "type",
226+
defaultLanguageOptions: {
227+
howMuch: true,
228+
// @ts-expect-error -- defaultLanguageOptions must match the language options.
229+
howMany: "a lot",
230+
},
231+
232+
validateLanguageOptions(languageOptions) {
233+
languageOptions.howMuch satisfies boolean;
234+
languageOptions.howMany satisfies number;
235+
},
236+
237+
parse(file, context): ParseResult<TestRootNode> {
238+
context.languageOptions.howMuch satisfies boolean;
239+
context.languageOptions.howMany satisfies number;
240+
241+
return {
242+
ok: true,
243+
ast: {
244+
type: "root",
245+
start: 0,
246+
length: file.body.length,
247+
},
248+
};
249+
},
250+
251+
createSourceCode(file, input, context): TestSourceCode {
252+
context.languageOptions.howMuch satisfies boolean;
253+
context.languageOptions.howMany satisfies number;
254+
return new TestSourceCode(String(file.body), input.ast);
255+
},
256+
};
257+
258+
testLanguage2.defaultLanguageOptions satisfies
259+
| { howMuch: boolean; howMany: number }
260+
| undefined;
261+
213262
//-----------------------------------------------------------------------------
214263
// Tests for rule-related types
215264
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)