diff --git a/scripts/generator.ts b/scripts/generator.ts index d3399bf5..414f48a5 100644 --- a/scripts/generator.ts +++ b/scripts/generator.ts @@ -419,7 +419,13 @@ const sourceFiles = Array.from(elementFilesMap.entries(), ([element, data]) => g const elementNames = sourceFiles.map(({ fileName }) => basename(fileName, '.ts')); function generateIndexFile(elementNames: readonly string[], extension: string): SourceFile { - const sourceLines = [...elementNames.map((elementName) => `export * from './${elementName}.js';`)]; + const sourceLines = [ + ...elementNames.map((elementName) => `export * from './${elementName}.js';`), + // Explicit re-exports beat star exports per-name in TypeScript, so these deterministically + // resolve each component name (e.g. `SelectItem`) even if another module's `export *` chain + // re-exports a colliding name (e.g. a deprecated type from a web component package). + ...elementNames.map((elementName) => `export { ${elementName} } from './${elementName}.js';`), + ]; return ts.createSourceFile( resolve(packageDir, `index.${extension}`), diff --git a/test/typings/SelectItem.tsx b/test/typings/SelectItem.tsx new file mode 100644 index 00000000..61677017 --- /dev/null +++ b/test/typings/SelectItem.tsx @@ -0,0 +1,16 @@ +import { SelectItem, type SelectItemData } from '@vaadin/react-components'; +import type { SelectItem as SelectItemType } from '@vaadin/react-components/Select.js'; + +// `SelectItem` must resolve to the React component and work in value/JSX position. +const element = x; + +// `SelectItemData` must still work in type position (unaffected by the collision fix). +const items: SelectItemData[] = []; + +// The deprecated `SelectItem` type is intentionally no longer exported from the barrel; +// `SelectItem` now refers only to the component, so using it as a type must fail to compile. +// @ts-expect-error — `SelectItem` is a value (the component) in the barrel, not a type. +let deprecated: SelectItem[]; + +// Escape hatch: the deprecated type is still importable directly from the Select.js subpath. +let stillWorks: SelectItemType[] = [];