Skip to content

Commit 554ecd6

Browse files
committed
reuse the type of args
1 parent dd2a7ff commit 554ecd6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

types/stylelint/index.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,20 @@ type FileCache = {
3636
removeEntry: (absoluteFilepath: string) => void;
3737
};
3838

39+
type RuleFuncArgs = (string | number | boolean | RegExp | string[])[];
40+
3941
// Note: With strict function types enabled, function signatures are checked contravariantly.
4042
// This means that it would not be possible for rule authors to narrow the message function
4143
// parameters to e.g. just `string`. Declaring the type for rule message functions through
4244
// method declarations tricks TypeScript into bivariant signature checking. More details can
4345
// be found here: https://stackoverflow.com/questions/52667959/what-is-the-purpose-of-bivariancehack-in-typescript-types.
4446
// and in the original discussion: https://github.com/stylelint/stylelint/pull/6147#issuecomment-1155337016.
4547
type RuleMessageFunc = {
46-
bivariance(...args: (string | number | boolean | RegExp | string[])[]): string;
48+
bivariance(...args: RuleFuncArgs): string;
4749
}['bivariance'];
4850

4951
type RuleSeverityFunc = {
50-
bivariance(...args: (string | number | boolean | RegExp | string[])[]): stylelint.Severity | null;
52+
bivariance(...args: RuleFuncArgs): stylelint.Severity | null;
5153
}['bivariance'];
5254

5355
type RuleOptionsPossibleFunc = (value: unknown) => boolean;

0 commit comments

Comments
 (0)