-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more explicit types for the default theme (#8780)
* Add more explicit types for the default theme * Update changelog * Cleanup * Cleanup code a bit * Add special cases for a few keys * Fix order
- Loading branch information
1 parent
6e75e6e
commit 62f0791
Showing
4 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import type { Config } from './types/config' | ||
declare const theme: Config['theme'] | ||
import { DefaultTheme } from './types/generated/default-theme' | ||
declare const theme: Config['theme'] & DefaultTheme | ||
export = theme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export function union(types) { | ||
return [...new Set(types)].join(' | ') | ||
} | ||
|
||
export function unionValues(values) { | ||
return union(values.map(forValue)) | ||
} | ||
|
||
export function forKeys(value) { | ||
return union(Object.keys(value).map((key) => `'${key}'`)) | ||
} | ||
|
||
export function forValue(value) { | ||
if (Array.isArray(value)) { | ||
return `(${unionValues(value)})[]` | ||
} | ||
|
||
if (typeof value === 'object') { | ||
return `Record<${forKeys(value)}, ${unionValues(Object.values(value))}>` | ||
} | ||
|
||
if (typeof value === 'string') { | ||
return `string` | ||
} | ||
|
||
return `any` | ||
} |