Closed webdif closed 2 years ago
Hmm, what TypeScript version are you using? 'Cannot be named' error were much more common in older versions of TS but I thought the checking here was relaxed.
I use TypeScript@3, do you think upgrading TypeScript does the trick?
It's fixed starting TypeScript 3.9. You can upgrade to 3.9.7 or later.
BTW, if you don't want to upgrade, the fix is to give an explicit type to your function:
import { SportsEvent, WithContext } from 'schema-dts';
-export const getStructuredData = (): WithContext<SportsEvent> => ({
+export const getStructuredData: ()=>WithContext<SportsEvent> = (): WithContext<SportsEvent> => ({
'@context': 'https://schema.org',
'@type': 'SportsEvent',
// ...
});
Thank you so much 🙂
This started to happen again.
import {BreadcrumbList} from 'schema-dts';
const data: BreadcrumbList = {'@type': 'BreadcrumbList'};
export const exportedFunction = () => ({data});
Will show the error:
Exported variable 'exportedFunction' has or is using name 'BreadcrumbListLeaf' from external module "..." but cannot be named. ts(4023)
If the function isn't exported, the error seems to not appear, though.
I have this piece of code:
I have the error TS4023 on this:
How can I resolve this?
If I modify the
schema.d.ts
in my node_modules, and I export the SportsEventLeaf interface, it seems to solve this problem. But of course, it's not a real fix…