Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 2 additions & 13 deletions src/components/extractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function extractExports(
const unknownExports: Array<string> = [];
for (const exportSymbol of exportSymbols) {
if (exportSymbol.name === 'default') {
validateComponentType(componentName, exportSymbol, checker);
validateComponentType(checker.getDeclaredTypeOfSymbol(exportSymbol), checker);
componentSymbol = exportSymbol;
} else if (exportSymbol.name === `${componentName}Props`) {
propsSymbol = exportSymbol;
Expand All @@ -167,18 +167,7 @@ export function extractExports(
return { componentSymbol, propsSymbol };
}

function validateComponentType(componentName: string, symbol: ts.Symbol, checker: ts.TypeChecker) {
const declaration = extractDeclaration(symbol);
let type: ts.Type;
if (ts.isExportAssignment(declaration)) {
// export default Something;
type = checker.getTypeAtLocation(declaration.expression);
} else if (ts.isFunctionDeclaration(declaration)) {
// export default function Something() {...}
type = checker.getTypeAtLocation(declaration);
} else {
throw new Error(`Unknown default export for ${componentName}`);
}
function validateComponentType(type: ts.Type, checker: ts.TypeChecker) {
if (
// React.forwardRef
type.getSymbol()?.name !== 'ForwardRefExoticComponent' &&
Expand Down
Loading