-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Type of Crawl Response (requires type assertion) #712
Comments
Suggested solutionTo avoid type assertions or type guards.. could extend like this: // Define a base interface for common fields
interface BaseCrawlResponse {
success: boolean;
error?: string;
}
// Define the successful response fields
interface SuccessfulCrawlFields {
status: "scraping" | "completed" | "failed" | "cancelled";
completed: number;
total: number;
creditsUsed: number;
expiresAt: Date;
next?: string;
data: FirecrawlDocument<undefined>[];
}
// Create a unified CrawlResponse type using conditional types
type CrawlResponse = BaseCrawlResponse & (
{ success: true } & SuccessfulCrawlFields |
{ success: false }
); Then replace any |
@oliviermills Hi, I am unable to reproduce the following error, and this can be due to 2 reasons.
|
Clarification: This is a dev/linting/typing issue, not a runnable issue.There is definitely a typing issue with accessing A workaround to avoid the lint error is to use this pattern: if ('error' in crawlResponse) {
// This is an ErrorResponse
throw new Error(`Failed to crawl: ${crawlResponse.error}`);
} else {
// This is a CrawlStatusResponse
console.log(crawlResponse);
} |
@oliviermills, I know this isn't a runnable error, so I haven't executed the code once. Please refer to images below.
|
Describe the Bug
Type error when using crawlResponse requiring type assertion
To Reproduce
Steps to reproduce the issue:
Expected Behavior
Should improve typing so we don't have to ts-ignore or type cast
Screenshots
If applicable, add screenshots or copies of the command line output to help explain the issue.
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: