{"id":784,"hash":"61b40222a80d435f0cc7b8ea9ce26404d941892aff093cda02ebc3afb5c71c99","pattern":"Typescript inferred type cannot be named without reference","full_message":"My project's setup is tsdx (based on Rollup and Typescript).\n\nWorking in my IDE (vscode) everything looks fine, and even running yarn tsc works without errors.\n\nWhen I'm running yarn build (which is tsdx build) I get the following error:\n\n(typescript) Error: /home/me/dev/app/src/components/alert/Alert.tsx(36,7): semantic error TS2742: The inferred type of 'AlertContainer' cannot be named without a reference to '@emotion/serialize/node_modules/csstype'. This is likely not portable. A type annotation is necessary.\nError: /home/me/dev/app/src/components/alert/Alert.tsx(36,7): semantic error TS2742: The inferred type of 'AlertContainer' cannot be named without a reference to '@emotion/serialize/node_modules/csstype'. This is likely not portable. A type annotation is necessary.\n\nThe code referenced in the error is:\n\ntype AlertContainerProps = {\n  theme: any\n};\nconst AlertContainer = styled(animated.div)<AlertContainerProps>`\n  ${(props) => props.theme.primaryView}\n  ...\n`;\n\n...\n\ntype AlertContentProps = Pick<React.ComponentProps<typeof AlertContainer>, 'style'> & {\n  status?: string\n};\n\nWhat am I doing wrong? How can I fix it?\n\nI tried this solution but it didn't work.","ecosystem":"npm","package_name":"reactjs","package_version":null,"solution":"This issue occurs when you are exporting a function whose return type could not be inferred by TypeScript\n\nFor example, consider the code snippet\n\nconst foo = async () => {\n  const data = someExternalLibary.doStuff();\n  return data;\n};\n\nIf TypeScript throws the following error:-\n\nThe inferred type of `foo` cannot be named without a reference to `../node_modules/someExternalLibary`. This is likely not portable. A type annotation is necessary.\n\nthis means that TS is saying that someExternalLibary.doStuff()'s return type could not be inferred because the return type of doStuff is not exported by someExternalLibrary library\n\nSo what's solution? just add the type annotation to data. Say, required type annotated is DoStuffReturnType\n\nconst foo = async () => {\n  const data: DoStuffReturnType = someExternalLibary.doStuff(); // Add type annotation to `data`\n  return data;\n};\n\nNow you should be good to go!","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/72041763/typescript-inferred-type-cannot-be-named-without-reference","votes":25,"created_at":"2026-04-19T04:51:42.998559+00:00","updated_at":"2026-04-19T04:51:42.998559+00:00"}