Skip to content

Commit fcdc5d9

Browse files
committed
add return types
1 parent c40acfb commit fcdc5d9

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

src/common/utils/CssCustomProperties.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
type AllowedCSSRule = CSSStyleRule | CSSPageRule; // they have necessary `selectorText` and `style` properties
77

88
interface getLocalCssStyleRulesProps {
9-
cssRuleType?: "CSSStyleRule" | "CSSPageRule";
9+
cssRuleType?: "CSSStyleRule";
1010
selectorText?: string;
1111
}
1212
interface getLocalCssStyleRulePropertiesProps extends getLocalCssStyleRulesProps {
@@ -28,7 +28,7 @@ export default class CssCustomProperties {
2828

2929
// Methods
3030

31-
customProperties = (props: getCustomPropertiesProps = {}) => {
31+
customProperties = (props: getCustomPropertiesProps = {}): string[][] | Record<string, string> => {
3232
// FIXME:
3333
// in case of performance issues results should get saved at least into intern variables
3434
// other cache strategies could be also tested
@@ -65,7 +65,7 @@ export default class CssCustomProperties {
6565
.flat();
6666
};
6767

68-
static listLocalCssStyleRules = (filter: getLocalCssStyleRulesProps = {}): AllowedCSSRule[] => {
68+
static listLocalCssStyleRules = (filter: getLocalCssStyleRulesProps = {}): CSSStyleRule[] => {
6969
const { cssRuleType = "CSSStyleRule", selectorText } = filter;
7070
const cssStyleRules = CssCustomProperties.listLocalCssRules().filter((rule) => {
7171
const cssrule = rule as AllowedCSSRule;
@@ -81,14 +81,14 @@ export default class CssCustomProperties {
8181
return false;
8282
}
8383
});
84-
return cssStyleRules as AllowedCSSRule[];
84+
return cssStyleRules as CSSStyleRule[];
8585
};
8686

87-
static listLocalCssStyleRuleProperties = (filter: getLocalCssStyleRulePropertiesProps = {}) => {
87+
static listLocalCssStyleRuleProperties = (filter: getLocalCssStyleRulePropertiesProps = {}): string[][] => {
8888
const { propertyType = "all", ...otherFilters } = filter;
8989
return CssCustomProperties.listLocalCssStyleRules(otherFilters)
9090
.map((cssrule) => {
91-
return [...(cssrule as AllowedCSSRule).style].map((propertyname) => {
91+
return [...(cssrule as CSSStyleRule).style].map((propertyname) => {
9292
return [propertyname.trim(), (cssrule as CSSStyleRule).style.getPropertyValue(propertyname).trim()];
9393
});
9494
})
@@ -104,7 +104,7 @@ export default class CssCustomProperties {
104104
});
105105
};
106106

107-
static listCustomProperties = (props: getCustomPropertiesProps = {}) => {
107+
static listCustomProperties = (props: getCustomPropertiesProps = {}): string[][] | Record<string, string> => {
108108
const { removeDashPrefix = true, returnObject = true, filterName = () => true, ...filterProps } = props;
109109

110110
const customProperties = CssCustomProperties.listLocalCssStyleRuleProperties({
@@ -121,6 +121,8 @@ export default class CssCustomProperties {
121121
return declaration;
122122
});
123123

124-
return returnObject ? Object.fromEntries(customProperties) : customProperties;
124+
return returnObject
125+
? (Object.fromEntries(customProperties) as Record<string, string>)
126+
: (customProperties as string[][]);
125127
};
126128
}

0 commit comments

Comments
 (0)