google / schema-dts

JSON-LD TypeScript types for Schema.org vocabulary
Apache License 2.0
860 stars 32 forks source link

TS4058: Return type of exported function has or is using name WebSiteLeaf from external module ... but cannot be named #193

Closed btakita closed 4 months ago

btakita commented 4 months ago

When declaring an object to be a WebSite type, a TS4058 appears.

export function jsonld_WebSite_() { // TS4058
    return <WebSite>{
        '@type': 'WebSite',
        '@id': jsonld_WebSite_id,
        url: website,
        name: title,
        mainEntity: jsonld_Person_(),
    }
}

Looking at the source,

export type WebSite = WebSiteLeaf;

WebSiteLeaf is not in use anywhere else nor is it exported. It seems that WebSiteLeaf should be renamed to WebSite. The intermediate type is not necessary.

btakita commented 4 months ago

Another solution is to add exports for all of the Leaf & Base types.

See https://github.com/microsoft/TypeScript/issues/9944 & https://github.com/microsoft/TypeScript/issues/9944

When I manually add an export to WebSiteLeaf, the error goes away:

export interface WebSiteLeaf extends WebSiteBase {
    "@type": "WebSite";
}
btakita commented 4 months ago

I published the @btakita/schema-dts package with https://github.com/google/schema-dts/pull/194. I will use this we can find a resolution for this issue.

btakita commented 4 months ago

I was able to resolve the issue by setting composite: false in my tsconfig.json file.

See https://github.com/microsoft/TypeScript/issues/42873#issuecomment-1143587071

Closing since my issue if fixed.