Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Expose TypeScript declarations #225

Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
"main": "dist/open-props.cjs",
"unpkg": "open-props.min.css",
"module": "dist/open-props.module.js",
"types": "dist/types/index.d.ts",
"exports": {
".": {
"import": "./dist/open-props.module.js",
"require": "./dist/open-props.cjs",
"types": "./dist/types/index.d.ts",
"default": "./dist/open-props.cjs"
},
"./src": "./src/index.js",
Expand Down Expand Up @@ -153,6 +155,7 @@
"postcss-cli": "^8.3.1",
"postcss-combine-duplicated-selectors": "^10.0.3",
"postcss-import": "^14.0.2",
"postcss-preset-env": "6.7.x"
"postcss-preset-env": "6.7.x",
"type-fest": "^2.12.2"
}
}
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ const camelize = text => {
return text.substr(0, 1).toLowerCase() + text.substr(1)
}

const mapToObjectNotation = props => {
/**
* @template T
* @param {T} props
* @returns {import("type-fest").CamelCasedPropertiesDeep<T>}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @returns {import("type-fest").CamelCasedPropertiesDeep<T>}
* @returns {import("type-fest").CamelCasedPropertiesDeep<T> & import("type-fest").KebabCase<T>}

to get both op.size1 and op["--size-1"] to work, to address part of @argyleink's feedback #225 (review)

I'll keep investigating my alternative solution, but I'm also liking the approach in this PR 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! T already infers the kebab keys from the original type, so I just needed to intersect T with the camel cased type: bd34e2f

*/
const keysToCamelCase = (props) => {
for (var prop in props)
props[camelize(prop)] = props[prop]
return props
}

const OpenProps = mapToObjectNotation({
const OpenProps = keysToCamelCase({
...Animations,
...Sizes,
...Colors,
Expand Down
13 changes: 13 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
"declarationDir": "dist/types",
"allowJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"esModuleInterop": true
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
}