Skip to content

Commit

Permalink
fix: improve types
Browse files Browse the repository at this point in the history
Plugin creator needs postcss property set to true.
It's more intuitive to use the types if it explicitly returns a PostCSS plugin.
  • Loading branch information
ludofischer committed Jan 28, 2022
1 parent 1f2513d commit f2cce1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
9 changes: 4 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import transform from './lib/transform';
* warnWhenCannotResolve?: boolean,
* mediaQueries?: boolean,
* selectors?: boolean}} PostCssCalcOptions
*
*/
/**
* @type {import('postcss').PluginCreator<PostCssCalcOptions>}
* @param {PostCssCalcOptions} opts
* @return {import('postcss').Plugin}
*/
function pluginCreator(opts) {
const options = Object.assign({
Expand All @@ -20,10 +23,6 @@ function pluginCreator(opts) {

return {
postcssPlugin: 'postcss-calc',
/**
* @param {import('postcss').Root} css
* @param {{result: import('postcss').Result}} helpers
*/
OnceExit(css, { result }) {
css.walk(node => {
const { type } = node;
Expand Down
20 changes: 7 additions & 13 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@ export type PostCssCalcOptions = {
* warnWhenCannotResolve?: boolean,
* mediaQueries?: boolean,
* selectors?: boolean}} PostCssCalcOptions
*
* @param {PostCssCalcOptions} opts
*/
declare function pluginCreator(opts: PostCssCalcOptions): {
postcssPlugin: string;
/**
* @param {import('postcss').Root} css
* @param {{result: import('postcss').Result}} helpers
*/
OnceExit(css: import('postcss').Root, { result }: {
result: import('postcss').Result;
}): void;
};
/**
* @type {import('postcss').PluginCreator<PostCssCalcOptions>}
* @param {PostCssCalcOptions} opts
* @return {import('postcss').Plugin}
*/
declare function pluginCreator(opts: PostCssCalcOptions): import('postcss').Plugin;
declare namespace pluginCreator {
const postcss: boolean;
const postcss: true;
}

0 comments on commit f2cce1b

Please sign in to comment.