Skip to content

Commit 62e9a3d

Browse files
authored
Annotate return types to satisfy isolatedDeclarations (#1607)
1 parent 4aece89 commit 62e9a3d

36 files changed

+108
-76
lines changed

packages/css/src/adapter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ const currentAdapter = () => {
2222

2323
let hasConfiguredAdapter = false;
2424

25-
export const setAdapterIfNotSet = (newAdapter: Adapter) => {
25+
export const setAdapterIfNotSet = (newAdapter: Adapter): void => {
2626
if (!hasConfiguredAdapter) {
2727
setAdapter(newAdapter);
2828
}
2929
};
3030

31-
export const setAdapter = (newAdapter: Adapter) => {
31+
export const setAdapter = (newAdapter: Adapter): void => {
3232
if (!newAdapter) {
3333
throw new Error('No adapter provided when calling "setAdapter"');
3434
}
@@ -38,7 +38,7 @@ export const setAdapter = (newAdapter: Adapter) => {
3838
adapterStack.push(newAdapter);
3939
};
4040

41-
export const removeAdapter = () => {
41+
export const removeAdapter = (): void => {
4242
adapterStack.pop();
4343
};
4444

packages/css/src/conditionalRulesets.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ type Condition = {
1212
children: ConditionalRuleset;
1313
};
1414

15+
type RenderedConditionalRule = Record<string, Record<string, any>>;
16+
1517
export class ConditionalRuleset {
1618
ruleset: Map<Query, Condition>;
1719

@@ -27,7 +29,7 @@ export class ConditionalRuleset {
2729
this.precedenceLookup = new Map();
2830
}
2931

30-
findOrCreateCondition(conditionQuery: Query) {
32+
findOrCreateCondition(conditionQuery: Query): Condition {
3133
let targetCondition = this.ruleset.get(conditionQuery);
3234

3335
if (!targetCondition) {
@@ -43,7 +45,7 @@ export class ConditionalRuleset {
4345
return targetCondition;
4446
}
4547

46-
getConditionalRulesetByPath(conditionPath: Array<Query>) {
48+
getConditionalRulesetByPath(conditionPath: Array<Query>): ConditionalRuleset {
4749
let currRuleset: ConditionalRuleset = this;
4850

4951
for (const query of conditionPath) {
@@ -55,7 +57,11 @@ export class ConditionalRuleset {
5557
return currRuleset;
5658
}
5759

58-
addRule(rule: Rule, conditionQuery: Query, conditionPath: Array<Query>) {
60+
addRule(
61+
rule: Rule,
62+
conditionQuery: Query,
63+
conditionPath: Array<Query>,
64+
): void {
5965
const ruleset = this.getConditionalRulesetByPath(conditionPath);
6066
const targetCondition = ruleset.findOrCreateCondition(conditionQuery);
6167

@@ -69,7 +75,7 @@ export class ConditionalRuleset {
6975
addConditionPrecedence(
7076
conditionPath: Array<Query>,
7177
conditionOrder: Array<Query>,
72-
) {
78+
): void {
7379
const ruleset = this.getConditionalRulesetByPath(conditionPath);
7480

7581
for (let i = 0; i < conditionOrder.length; i++) {
@@ -86,7 +92,7 @@ export class ConditionalRuleset {
8692
}
8793
}
8894

89-
isCompatible(incomingRuleset: ConditionalRuleset) {
95+
isCompatible(incomingRuleset: ConditionalRuleset): boolean {
9096
for (const [
9197
condition,
9298
orderPrecedence,
@@ -117,7 +123,7 @@ export class ConditionalRuleset {
117123
return true;
118124
}
119125

120-
merge(incomingRuleset: ConditionalRuleset) {
126+
merge(incomingRuleset: ConditionalRuleset): void {
121127
// Merge rulesets into one array
122128
for (const { query, rules, children } of incomingRuleset.ruleset.values()) {
123129
const matchingCondition = this.ruleset.get(query);
@@ -150,7 +156,7 @@ export class ConditionalRuleset {
150156
*
151157
* @returns true if successful, false if the ruleset is incompatible
152158
*/
153-
mergeIfCompatible(incomingRuleset: ConditionalRuleset) {
159+
mergeIfCompatible(incomingRuleset: ConditionalRuleset): boolean {
154160
if (!this.isCompatible(incomingRuleset)) {
155161
return false;
156162
}
@@ -160,7 +166,7 @@ export class ConditionalRuleset {
160166
return true;
161167
}
162168

163-
getSortedRuleset() {
169+
getSortedRuleset(): Condition[] {
164170
const sortedRuleset: Array<Condition> = [];
165171

166172
// Loop through all queries and add them to the sorted ruleset
@@ -189,11 +195,11 @@ export class ConditionalRuleset {
189195
return sortedRuleset;
190196
}
191197

192-
renderToArray() {
193-
const arr: any = [];
198+
renderToArray(): RenderedConditionalRule[] {
199+
const arr: RenderedConditionalRule[] = [];
194200

195201
for (const { query, rules, children } of this.getSortedRuleset()) {
196-
const selectors: any = {};
202+
const selectors: Record<string, any> = {};
197203

198204
for (const rule of rules) {
199205
selectors[rule.selector] = {

packages/css/src/container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { generateIdentifier } from './identifier';
22

33
// createContainer is used for local scoping of CSS containers
44
// For now it is mostly just an alias of generateIdentifier
5-
export const createContainer = (debugId?: string) =>
5+
export const createContainer = (debugId?: string): string =>
66
generateIdentifier(debugId);

packages/css/src/fileScope.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let refCounter = 0;
66

77
const fileScopes: Array<FileScope> = [];
88

9-
export function setFileScope(filePath: string, packageName?: string) {
9+
export function setFileScope(filePath: string, packageName?: string): void {
1010
refCounter = 0;
1111
const fileScope = {
1212
filePath,
@@ -16,13 +16,13 @@ export function setFileScope(filePath: string, packageName?: string) {
1616
onBeginFileScope(fileScope);
1717
}
1818

19-
export function endFileScope() {
19+
export function endFileScope(): void {
2020
onEndFileScope(getFileScope());
2121
refCounter = 0;
2222
fileScopes.splice(0, 1);
2323
}
2424

25-
export function hasFileScope() {
25+
export function hasFileScope(): boolean {
2626
return fileScopes.length > 0;
2727
}
2828

@@ -41,6 +41,6 @@ export function getFileScope(): FileScope {
4141
return fileScopes[0];
4242
}
4343

44-
export function getAndIncrementRefCounter() {
44+
export function getAndIncrementRefCounter(): number {
4545
return refCounter++;
4646
}

packages/css/src/functionSerializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface SerializerConfig {
1616
export function addFunctionSerializer<Target extends object>(
1717
target: Target,
1818
recipe: SerializerConfig,
19-
) {
19+
): Target {
2020
// TODO: Update to "__function_serializer__" in future.
2121
// __recipe__ is the backwards compatible name
2222
Object.defineProperty(target, '__recipe__', {

packages/css/src/getDebugFileName.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const memoizedGetDebugFileName = () => {
5656
max: 500,
5757
});
5858

59-
return (path: string) => {
59+
return (path: string): string => {
6060
const cachedResult = cache.get(path);
6161

6262
if (cachedResult) {
@@ -70,4 +70,5 @@ const memoizedGetDebugFileName = () => {
7070
};
7171
};
7272

73-
export const getDebugFileName = memoizedGetDebugFileName();
73+
export const getDebugFileName: (path: string) => string =
74+
memoizedGetDebugFileName();

packages/css/src/injectStyles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface InjectStylesOptions {
66
fileScope: FileScope;
77
css: string;
88
}
9-
export const injectStyles = ({ fileScope, css }: InjectStylesOptions) => {
9+
export const injectStyles = ({ fileScope, css }: InjectStylesOptions): void => {
1010
const fileScopeId = fileScope.packageName
1111
? [fileScope.packageName, fileScope.filePath].join('/')
1212
: fileScope.filePath;

packages/css/src/recipe.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { addFunctionSerializer } from './functionSerializer';
22

3-
/**
4-
* @deprecated Use 'addFunctionSerializer' from '@vanilla-extract/css/functionSerializer'
5-
*/
6-
export const addRecipe = addFunctionSerializer;
3+
export {
4+
/**
5+
* @deprecated Use 'addFunctionSerializer' from '@vanilla-extract/css/functionSerializer'
6+
*/
7+
addFunctionSerializer as addRecipe,
8+
};

packages/css/src/style.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function composedStyle(rules: Array<StyleRule | ClassNames>, debugId?: string) {
6767
return result;
6868
}
6969

70-
export function style(rule: ComplexStyleRule, debugId?: string) {
70+
export function style(rule: ComplexStyleRule, debugId?: string): string {
7171
if (Array.isArray(rule)) {
7272
return composedStyle(rule, debugId);
7373
}
@@ -83,20 +83,20 @@ export function style(rule: ComplexStyleRule, debugId?: string) {
8383
/**
8484
* @deprecated The same functionality is now provided by the 'style' function when you pass it an array
8585
*/
86-
export function composeStyles(...classNames: Array<ClassNames>) {
86+
export function composeStyles(...classNames: Array<ClassNames>): string {
8787
const compose = hasFileScope() ? composedStyle : dudupeAndJoinClassList;
8888

8989
return compose(classNames);
9090
}
9191

92-
export function globalStyle(selector: string, rule: GlobalStyleRule) {
92+
export function globalStyle(selector: string, rule: GlobalStyleRule): void {
9393
appendCss({ type: 'global', selector, rule }, getFileScope());
9494
}
9595

9696
export function fontFace(
9797
rule: FontFaceRule | FontFaceRule[],
9898
debugId?: string,
99-
) {
99+
): string {
100100
const fontFamily = `"${cssesc(generateIdentifier(debugId), {
101101
quotes: 'double',
102102
})}"`;
@@ -124,7 +124,7 @@ export function fontFace(
124124
export function globalFontFace(
125125
fontFamily: string,
126126
rule: FontFaceRule | FontFaceRule[],
127-
) {
127+
): void {
128128
const rules = Array.isArray(rule) ? rule : [rule];
129129

130130
for (const singleRule of rules) {
@@ -135,7 +135,7 @@ export function globalFontFace(
135135
}
136136
}
137137

138-
export function keyframes(rule: CSSKeyframes, debugId?: string) {
138+
export function keyframes(rule: CSSKeyframes, debugId?: string): string {
139139
const name = cssesc(generateIdentifier(debugId), {
140140
isIdentifier: true,
141141
});
@@ -145,7 +145,7 @@ export function keyframes(rule: CSSKeyframes, debugId?: string) {
145145
return name;
146146
}
147147

148-
export function globalKeyframes(name: string, rule: CSSKeyframes) {
148+
export function globalKeyframes(name: string, rule: CSSKeyframes): void {
149149
appendCss({ type: 'keyframes', name, rule }, getFileScope());
150150
}
151151

packages/css/src/transformCss.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ class Stylesheet {
639639
}
640640
}
641641

642-
function renderCss(v: any, indent: string = '') {
642+
function renderCss(v: Record<string, any>, indent: string = '') {
643643
const rules: Array<string> = [];
644644

645645
for (const key of Object.keys(v)) {
@@ -679,7 +679,7 @@ export function transformCss({
679679
localClassNames,
680680
cssObjs,
681681
composedClassLists,
682-
}: TransformCSSParams) {
682+
}: TransformCSSParams): string[] {
683683
const stylesheet = new Stylesheet(localClassNames, composedClassLists);
684684

685685
for (const root of cssObjs) {

0 commit comments

Comments
 (0)