8000 feat(experimental-utils): allow rule options to be a readonly tuple (… · dandv/typescript-eslint@4ef6788 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ef6788

Browse files
authored
feat(experimental-utils): allow rule options to be a readonly tuple (typescript-eslint#1924)
1 parent 017b22d commit 4ef6788

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/experimental-utils/src/eslint-utils/RuleCreator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function RuleCreator(urlCreator: (ruleName: string) => string) {
1717
// This function will get much easier to call when this is merged https://github.com/Microsoft/TypeScript/pull/26349
1818
// TODO - when the above PR lands; add type checking for the context.report `data` property
1919
return function createRule<
20-
TOptions extends unknown[],
20+
TOptions extends readonly unknown[],
2121
TMessageIds extends string,
2222
TRuleListener extends RuleListener = RuleListener
2323
>({

packages/experimental-utils/src/eslint-utils/applyDefault.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ import { deepMerge, isObjectNotArray } from './deepMerge';
77
* @param userOptions the user opts
88
* @returns the options with defaults
99
*/
10-
function applyDefault<TUser extends unknown[], TDefault extends TUser>(
10+
function applyDefault<TUser extends readonly unknown[], TDefault extends TUser>(
1111
defaultOptions: TDefault,
1212
userOptions: TUser | null,
1313
): TDefault {
1414
// clone defaults
15-
const options: TDefault = JSON.parse(JSON.stringify(defaultOptions));
15+
const options: AsMutable<TDefault> = JSON.parse(
16+
JSON.stringify(defaultOptions),
17+
);
1618

1719
if (userOptions === null || userOptions === undefined) {
1820
return options;
@@ -33,4 +35,6 @@ function applyDefault<TUser extends unknown[], TDefault extends TUser>(
3335
return options;
3436
}
3537

38+
type AsMutable<T extends {}> = { -readonly [TKey in keyof T]: T[TKey] };
39+
3640
export { applyDefault };

0 commit comments

Comments
 (0)
0