Skip to content

Commit 568b0ea

Browse files
authored
Add type definitions for the CSS files (#56)
By default TypeScript ignores unresolved bare imports. This can be made into a type error with `noUncheckedSideEffectImports`. However, TypeScript also disallows importing unknown file extensions. This can be enabled using `allowArbitraryExtensions`. This makes TypeScript resolve the style imports, but the type definitions are missing. This change updates the script for generating the styles to also add type definitions. This allows people to import the styles.
1 parent 337f2fe commit 568b0ea

16 files changed

+20
-1
lines changed

script/css.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import assert from 'node:assert/strict'
4040
import fs from 'node:fs/promises'
41+
import path from 'node:path'
4142
import {fileURLToPath} from 'node:url'
4243
import css from 'css'
4344
// @ts-expect-error: untyped.
@@ -145,6 +146,8 @@ for (const fileName of fileNames) {
145146
document.push(rule)
146147
}
147148

149+
const {ext, name} = path.parse(fileName)
150+
148151
writePromises.push(
149152
fs.writeFile(
150153
new URL(fileName, base),
@@ -155,7 +158,8 @@ for (const fileName of fileNames) {
155158
document.join('\n\n'),
156159
{...prettierConfig, parser: 'css'}
157160
)
158-
)
161+
),
162+
fs.writeFile(new URL(name + '.d' + ext + '.ts', base), 'export {}\n')
159163
)
160164
}
161165

style/both.d.css.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {}

style/colorblind-dark.d.css.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {}

style/colorblind-light.d.css.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {}

style/colorblind.d.css.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {}

style/core.d.css.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {}

style/dark.d.css.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {}

style/dimmed-dark.d.css.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {}

style/dimmed.d.css.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {}

style/high-contrast-dark.d.css.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {}

0 commit comments

Comments
 (0)