Skip to content

Commit c8c4cf4

Browse files
fix: export module augmentation
1 parent 0c5122e commit c8c4cf4

File tree

7 files changed

+28
-11
lines changed

7 files changed

+28
-11
lines changed

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"typecheck": "tsc --noEmit",
1717
"build:esm": "tsc",
1818
"build:cjs": "tsc --module commonjs --outDir dist/cjs",
19-
"build": "rm -rf dist && rm -f .tsbuildinfo && npm run build:esm && npm run build:cjs",
19+
"build:type-augmentation": "cp -r src/type-augmentation dist/type-augmentation",
20+
"build": "rm -rf dist && rm -f .tsbuildinfo && npm run build:esm && npm run build:cjs && npm run build:type-augmentation",
2021
"lint-check": "eslint src/ .storybook/",
2122
"lint-fix": "yarn lint-check --fix",
2223
"fmt-check": "prettier --ignore-path .gitignore --ignore-path .prettierignore --check .",
@@ -37,6 +38,11 @@
3738
"types": "./dist/esm/index.d.ts",
3839
"default": "./dist/esm/index.js"
3940
}
41+
},
42+
"./type-augmentation": {
43+
"import": "./dist/type-augmentation/index.d.ts",
44+
"require": "./dist/type-augmentation/index.d.ts",
45+
"default": "./dist/type-augmentation/index.d.ts"
4046
}
4147
},
4248
"dependencies": {

src/components/ThemeProvider/ThemeProvider.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as typography from "./typography"
99
import * as buttons from "./buttons"
1010
import * as chips from "./chips"
1111
import { colors } from "./colors"
12-
import type { CustomTheme } from "../../types/theme"
1312

1413
const shadow = {
1514
shadowOffsetX: 3,
@@ -94,10 +93,6 @@ const defaultThemeOptions: ThemeOptions = {
9493
},
9594
}
9695

97-
type ExtendedTheme = Theme & {
98-
custom: CustomTheme
99-
}
100-
10196
/**
10297
* Create a customized Smoot Design theme for use with `ThemeProvider`.
10398
*
@@ -106,7 +101,7 @@ type ExtendedTheme = Theme & {
106101
*/
107102
const createTheme = (options?: {
108103
custom: Partial<ThemeOptions["custom"]>
109-
}): ExtendedTheme =>
104+
}): Theme =>
110105
muiCreateTheme({
111106
...defaultThemeOptions,
112107
custom: {

src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
"use client"
2-
/// <reference types="./types/theme.d.ts" />
3-
/// <reference types="./types/typography.d.ts" />
42

53
export { default as styled } from "@emotion/styled"
64
export { css, Global } from "@emotion/react"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Meta } from "@storybook/blocks"
2+
3+
<Meta title="Smoot-Design/Typescript" />
4+
5+
# Type Augmentation
6+
7+
Smoot Design uses Typescript's module augmentation to enhance types provided by `@emotion` and `@mui` packages. For example, we add custom theme properties (`theme.custom`) to the default theme and add new properties / values to some MUI components.
8+
9+
To enable this module augmentation in a consuming application or library, either:
10+
11+
- **Method 1:** `"@mitodl/smoot-design/type-augmentation"` to the `"types"` array in the `tsconfig.json` file, or
12+
- **Method 2:** add `import "@mitodl/smoot-design/type-augmentation";` to a `global.d.ts` file.
13+
14+
For more information on this subject, see:
15+
16+
- TS Documenation: [Declaration Merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html)
17+
- MUI Documentation: [Theming/Typescript](https://mui.com/material-ui/customization/theming/#typescript)

src/type-augmentation/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import "./theme"
2+
import "./typography"

src/types/theme.d.ts renamed to src/type-augmentation/theme.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import type { Theme as MuiTheme } from "@mui/material/styles"
22
import "@emotion/react"
33
import "@emotion/styled"
4-
import "./typography"
54

65
export interface ColorGroup {
76
main: string
87
highlight: string
98
contrastText: string
109
}
1110

12-
interface CustomTheme {
11+
export interface CustomTheme {
1312
transitionDuration: string
1413
shadow: string
1514
colors: {
File renamed without changes.

0 commit comments

Comments
 (0)