Skip to content

Commit 52c6c53

Browse files
authored
refactor(codegen): simplify return value hints (#17)
1 parent dc1734f commit 52c6c53

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/__tests__/codegen.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ describe('codegen', () => {
3737
"file": "ct.mjs",
3838
},
3939
{
40-
"code": "const pluginCtMap = {
40+
"code": "type PluginCtMapType = {
4141
'foo.100': '#fff',
4242
'foo.200': {"base":"#000","lg":"#111"},
4343
'bar.100': 'red',
4444
'bar.200': 'blue',
45-
} as const;
45+
}
4646
47-
export const ct: <T extends keyof typeof pluginCtMap>(alias: T) => typeof pluginCtMap[T];",
47+
export const ct: <T extends keyof PluginCtMapType>(alias: T) => PluginCtMapType[T];",
4848
"file": "ct.d.ts",
4949
},
5050
],

src/codegen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const codegen = (
3232
const ctDtsFile: ArtifactContent = {
3333
file: 'ct.d.ts',
3434
code: `${serializeMapTypes(map)}
35-
\nexport const ct: <T extends keyof typeof pluginCtMap>(alias: T) => typeof pluginCtMap[T];`,
35+
\nexport const ct: <T extends keyof PluginCtMapType>(alias: T) => PluginCtMapType[T];`,
3636
};
3737

3838
cssFn.files.push(ctFile, ctDtsFile);

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export const serializeValue = (value: any) => {
1515
};
1616

1717
export const serializeMapTypes = (map: Map<any, any>) => {
18-
let code = 'const pluginCtMap = {';
18+
let code = 'type PluginCtMapType = {';
1919
for (const [key, value] of map.entries()) {
2020
code += `\n '${key}': ${serializeValue(value)},`;
2121
}
22-
code += '\n} as const;';
22+
code += '\n}';
2323
return code;
2424
};

0 commit comments

Comments
 (0)