Losing type information on RecipeVariantProps #2826
-
Hey! I am trying to build an external component library. Most of the things are working already, but I cannot get the correct type information from my RecipeVariantProps to work with Here is an example component that I create with cva: import {cva, type RecipeVariantProps} from "@styled/css";
const styles = cva({
base: {
bgColor: "yellow.500",
},
variants: {
size: {
small: {
height: 20,
width: 20,
},
huge: {
height: 120,
width: 120,
}
}
},
defaultVariants: {
size: "small",
}
})
type CvaVariantProps = NonNullable<RecipeVariantProps<typeof styles>>
type Props = {
label: string
} & CvaVariantProps
export const CvaComponent = (props: Props) => {
return (
<div className={styles({size: props.size})}>{props.label}</div>
)
} If I use this component inside my package I get full type safety for Here is my import { defineConfig } from 'tsup';
export default defineConfig((options) => {
const prod = options.env?.NODE_ENV === 'production';
return {
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
dts: true, // Always generate declaration files
splitting: true,
sourcemap: true,
clean: true,
treeshake: true,
minify: prod,
external: ['react', 'react-dom', 'react-hook-form', '@pandacss/dev', '@styled'],
outDir: 'dist',
bundle: false,
skipNodeModulesBundle: true,
metafile: true,
watch: !prod,
tsconfig: './tsconfig.json',
outExtension({ format }) {
return {
js: `.${format}.js`,
dts: '.d.ts',
};
},
};
}); Is there a way to keep the type information on the RecipeVariantProps? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The reason this happens is because In the consuming app, do you generate a |
Beta Was this translation helpful? Give feedback.
The reason this happens is because
@styled
is marked as external.In the consuming app, do you generate a
styled-system
folder? If you do, I recommend setting up an alias in the tsconfig that maps@styled
to the generatedstyled-system