FrancescoCastaldi commented on code in PR #44894:
URL: https://github.com/apache/superset/pull/44894#discussion_r4262691133
##########
superset-frontend/packages/superset-ui-core/src/components/Select/types.ts:
##########
@@ -29,9 +29,16 @@ export type RawValue = string | number;
export type V = string | number | null | undefined;
-export type LabeledValue = AntdLabeledValue;
+export type LabeledValue = AntdLabeledValue & {
Review Comment:
I addressed this by harmonizing SelectValue directly in types.ts:
```ts
export type SelectValue =
| RawValue
| RawValue[]
| LabeledValue
| LabeledValue[]
| null
| undefined;
```
By defining SelectValue as a clean union including LabeledValue and
LabeledValue[], we preserve existing consumer contracts, including
SelectAsyncControl/index.tsx (which expects values flowing through Ant Design
labeled structures).
This resolves TS2322 at the source without altering the consumer file, while
fully satisfying the test cases in AsyncSelect.test.tsx and Select.test.tsx.
The type guard isLabeledValue cleanly discriminates LabeledValue from RawValue,
avoiding any spurious narrowing mismatches across consumer modules.
Francesco Castaldi
##########
superset-frontend/packages/superset-ui-core/src/components/Select/AsyncSelect.stories.tsx:
##########
@@ -318,3 +318,51 @@ AsynchronousSelect.argTypes = {
},
},
};
+
+const createMockUserFetcher =
+ (responseTime = 0.3) =>
+ (
+ search: string,
+ page: number,
+ pageSize: number,
+ ): Promise<SelectOptionsTypePage> => {
+ const username = search.trim().toLowerCase();
+ const all = USERS.filter(
+ u => !username || u.toLowerCase().includes(username),
+ );
+ const totalCount = all.length;
+ const start = page * pageSize;
+ const deleteCount =
+ start + pageSize < totalCount ? pageSize : totalCount - start;
+ const pageData = all.slice(start, start + deleteCount).map(u => ({
+ label: u,
+ value: u,
+ }));
+ return new Promise(resolve => {
+ setTimeout(() => {
+ resolve({ data: pageData, totalCount });
+ }, responseTime * 1000);
+ });
+ };
+
+/**
+ * Demonstrates allowNewOptions in AsyncSelect. Optimistic custom options
appear
+ * with a [new] badge and are automatically dropped if the server returns a
matching
+ * option upon search completion.
+ */
+export const WithAllowNewOptions = (args: AsyncSelectProps) => (
+ <div style={{ width: DEFAULT_WIDTH }}>
+ <AsyncSelect
Review Comment:
Applied the suggested typing in AsyncSelect.stories.tsx:
```tsx
export const WithAllowNewOptions = (args: Omit<AsyncSelectProps, 'ref'>) => (
```
Omitting 'ref' from the story args eliminates the conflict where the spread
args carried Ref<RefSelectProps> from BaseSelectProps against AsyncSelectRef
(RefSelectProps & { clearCache }). This completely clears TS2322 on the
storybook file while preserving full props coverage.
Francesco Castaldi
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]