fix: Update FilePickerOptions onFilesPicked type#30
Conversation
Co-authored-by: guillaume <guillaume@stackone.com>
|
Cursor Agent can help with this pull request. Just |
Co-authored-by: guillaume <guillaume@stackone.com>
Co-authored-by: guillaume <guillaume@stackone.com>
There was a problem hiding this comment.
Pull Request Overview
This PR corrects the type definition for the FilePickerOptions.onFilesPicked callback to match the actual runtime behavior, where the callback receives an object containing arrays of selected files, folders, and drives rather than a direct array of files.
- Updated the callback signature to accept an object with optional
files,folders, anddrivesproperties - Added new type definitions for
FolderandDriveto support the expanded functionality - Updated documentation to reflect the correct callback structure and usage patterns
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/types.ts | Adds Folder and Drive types and updates onFilesPicked callback signature |
| src/index.ts | Exports the new Folder, Drive, and FilePickerOptions types |
| src/filePicker.ts | Updates imports and internal callback type to match new signature |
| README.md | Updates documentation with correct callback usage examples and type descriptions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…cker Co-authored-by: guillaume <guillaume@stackone.com>
| driveSelectionEnabled = true, | ||
| onFilesPicked = (files) => { | ||
| console.log('Selected files:', files); | ||
| onFilesPicked = (data) => { |
There was a problem hiding this comment.
Use ':' for the object property; '=' makes the example invalid JavaScript.
Prompt for AI agents
Address the following comment on README.md at line 63:
<comment>Use ':' for the object property; '=' makes the example invalid JavaScript.</comment>
<file context>
@@ -60,8 +60,17 @@ const options = {
driveSelectionEnabled = true,
- onFilesPicked = (files) => {
- console.log('Selected files:', files);
+ onFilesPicked = (data) => {
+ // data may contain files, folders, and/or drives based on what was selected
+ if (data.files) {
</file context>
Context
This PR addresses an inaccuracy in the
FilePickerOptionsinterface where theonFilesPickedcallback parameter type did not match the actual data structure received at runtime. Users reported that the callback receives an object with afilesproperty, rather than a direct array ofFileobjects.Why
To ensure type safety and provide an accurate API definition for developers, the
onFilesPickedcallback's parameter type has been updated to correctly reflect that it receives an object{ files: File[] }. This prevents type mismatches and eliminates the need for user-side workarounds.What
onFilesPickedcallback parameter type insrc/types.tsandsrc/filePicker.tsfrom(data: File[]) => voidto(data: { files: File[] }) => void.README.mddocumentation, including code examples and the parameter description, to reflect the correct callback signature.Checklist
Use the checklist below as a guide to ensure your PR is ready for review
Slack Thread
Summary by cubic
Fixes the FilePickerOptions.onFilesPicked type to match runtime. The callback now receives { files: File[] } instead of File[]; docs updated to reflect this.