From c6a075bcc72b984da787a94d30d38426a68cef80 Mon Sep 17 00:00:00 2001 From: Dawid Bartczak <66019090+assynu@users.noreply.github.com> Date: Tue, 11 Mar 2025 08:10:11 -0700 Subject: [PATCH] Fix missing type for login-password alert prompt (#49757) Summary: When using the `login-password` prompt type, there is a TypeScript type mismatch issue. The `callbackOrButtons` parameter returns an object with `{login: string, password: string}` structure, but this type variation is not properly included in the **AlertType** type definition. This causes TypeScript to show type errors when using callback functions that expect credentials in the format `(credentials: {login: string, password: string}) => void`. ## Changelog: - [General] [Fixed] Add missing type variation `{login: string, password: string}` to **AlertType** type definition to properly support `login-password` prompt callbacks Pull Request resolved: https://github.com/facebook/react-native/pull/49757 Test Plan: This change is purely type-related and doesn't affect runtime behavior. Reviewed By: NickGerleman Differential Revision: D70797036 Pulled By: alanleedev fbshipit-source-id: 8e27a39f0c8f49083730c683b41b69173715bd68 --- packages/react-native/Libraries/Alert/Alert.d.ts | 5 ++++- packages/react-native/types/__typetests__/index.tsx | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/react-native/Libraries/Alert/Alert.d.ts b/packages/react-native/Libraries/Alert/Alert.d.ts index b9bea342ac9..c6a84a820a4 100644 --- a/packages/react-native/Libraries/Alert/Alert.d.ts +++ b/packages/react-native/Libraries/Alert/Alert.d.ts @@ -12,7 +12,10 @@ */ export interface AlertButton { text?: string | undefined; - onPress?: ((value?: string) => void) | undefined; + onPress?: + | ((value?: string) => void) + | ((value?: {login: string; password: string}) => void) + | undefined; isPreferred?: boolean | undefined; style?: 'default' | 'cancel' | 'destructive' | undefined; } diff --git a/packages/react-native/types/__typetests__/index.tsx b/packages/react-native/types/__typetests__/index.tsx index 1a3d6f9401b..a91b662a5da 100644 --- a/packages/react-native/types/__typetests__/index.tsx +++ b/packages/react-native/types/__typetests__/index.tsx @@ -1137,7 +1137,8 @@ Alert.prompt( { text: 'OK', isPreferred: true, - onPress: password => console.log('OK Pressed, password: ' + password), + onPress: (password?: string) => + console.log('OK Pressed, password: ' + password), }, ], 'secure-text',