Skip to content

Commit f018bd2

Browse files
authored
Merge pull request #686 from Telegram-Mini-Apps/bugfix/fix-invalid-show-popup-typings
Bugfix/fix invalid show popup typings
2 parents 7f7b98c + 94a3558 commit f018bd2

File tree

5 files changed

+78
-21
lines changed

5 files changed

+78
-21
lines changed

.changeset/calm-horses-drop.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@telegram-apps/sdk": patch
3+
---
4+
5+
Fix ivalid typings in `openPopup` function.

packages/sdk/src/scopes/components/popup/exports.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ export {
44
open as openPopup,
55
openError as openPopupError,
66
openPromise as openPopupPromise,
7+
isShown as isPopupShown,
8+
show as showPopup,
9+
showError as showPopupError,
10+
showPromise as showPopupPromise,
711
} from './exports.variable.js';
812
export * as popup from './exports.variable.js';
913
export type {
1014
OpenOptions as OpenPopupOptions,
1115
OpenOptionsButton as OpenPopupOptionsButton,
12-
} from './types.js';
16+
ShowOptionsButton as ShowPopupOptionsButton,
17+
ShowOptions as ShowPopupOptions,
18+
} from './types.js';
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
export { isOpened, open, isSupported, openPromise, openError } from './popup.js';
1+
export {
2+
isOpened,
3+
open,
4+
isSupported,
5+
openPromise,
6+
openError,
7+
showError,
8+
show,
9+
showPromise,
10+
isShown,
11+
} from './popup.js';

packages/sdk/src/scopes/components/popup/popup.ts

+38-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import type { AbortablePromise } from 'better-promises';
2+
13
import { request } from '@/globals.js';
24
import { createIsSupported } from '@/scopes/createIsSupported.js';
35
import { createWrapSupported } from '@/scopes/wrappers/createWrapSupported.js';
46
import { defineNonConcurrentFn } from '@/scopes/defineNonConcurrentFn.js';
57

68
import { prepareParams } from './prepareParams.js';
7-
import type { OpenOptions } from './types.js';
9+
import type { ShowOptions } from './types.js';
810

911
const OPEN_METHOD = 'web_app_open_popup';
1012
const wrapSupported = createWrapSupported('popup', OPEN_METHOD);
@@ -14,16 +16,38 @@ const wrapSupported = createWrapSupported('popup', OPEN_METHOD);
1416
*/
1517
export const isSupported = createIsSupported(OPEN_METHOD);
1618

17-
const [
18-
fn,
19-
tOpenPromise,
20-
tOpenError,
21-
] = defineNonConcurrentFn((options: OpenOptions) => {
22-
return request(OPEN_METHOD, 'popup_closed', {
23-
...options,
24-
params: prepareParams(options),
25-
}).then(({ button_id: buttonId }) => buttonId === undefined ? null : buttonId);
26-
}, 'A popup is already opened');
19+
const [fn, tPromise, tShowError] = defineNonConcurrentFn(
20+
(options: ShowOptions): AbortablePromise<string | null> => {
21+
return request(OPEN_METHOD, 'popup_closed', {
22+
...options,
23+
params: prepareParams(options),
24+
}).then(({ button_id: buttonId }) => buttonId === undefined ? null : buttonId);
25+
},
26+
'A popup is already opened',
27+
);
28+
29+
/**
30+
* @deprecated Deprecated for consistence naming, to be removed in the next major update. Use
31+
* `show` instead.
32+
*/
33+
export const open = wrapSupported('open', fn);
34+
/**
35+
* @deprecated Deprecated for consistence naming, to be removed in the next major update. Use
36+
* `showPromise` instead.
37+
*/
38+
const openPromise = tPromise[1];
39+
/**
40+
* @deprecated Deprecated for consistence naming, to be removed in the next major update. Use
41+
* `isShown` instead.
42+
*/
43+
const isOpened = tPromise[2];
44+
/**
45+
* @deprecated Deprecated for consistence naming, to be removed in the next major update. Use
46+
* `showError` instead.
47+
*/
48+
const openError = tShowError[1];
49+
50+
export { openPromise, isOpened, openError };
2751

2852
/**
2953
* A method that shows a native popup described by the `params` argument.
@@ -56,6 +80,6 @@ const [
5680
* });
5781
* }
5882
*/
59-
export const open = wrapSupported('open', fn);
60-
export const [, openPromise, isOpened] = tOpenPromise;
61-
export const [, openError] = tOpenError;
83+
export const show = wrapSupported('show', fn);
84+
export const [, showPromise, isShown] = tPromise;
85+
export const [, showError] = tShowError;

packages/sdk/src/scopes/components/popup/types.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { RequestOptionsNoCapture } from '@/types.js';
1+
import type { RequestOptionsNoCapture } from '@/types.js';
22

33
/**
44
* This object describes the native popup.
55
* @see https://core.telegram.org/bots/webapps#popupparams
66
*/
7-
export interface OpenOptions extends RequestOptionsNoCapture {
7+
export interface ShowOptions extends RequestOptionsNoCapture {
88
/**
99
* The text to be displayed in the popup title, 0-64 characters.
1010
* @default ""
@@ -18,14 +18,14 @@ export interface OpenOptions extends RequestOptionsNoCapture {
1818
* List of buttons to be displayed in the popup, 1-3 buttons.
1919
* @default [{type: 'close'}]
2020
*/
21-
buttons?: OpenOptionsButton[];
21+
buttons?: ShowOptionsButton[];
2222
}
2323

2424
/**
2525
* This object describes the native popup button.
2626
* @see https://core.telegram.org/bots/webapps#popupbutton
2727
*/
28-
export type OpenOptionsButton = {
28+
export type ShowOptionsButton = {
2929
/**
3030
* Identifier of the button, 0-64 characters.
3131
* @default ""
@@ -54,4 +54,16 @@ export type OpenOptionsButton = {
5454
* - `cancel`, a button with the localized text "Cancel".
5555
*/
5656
type: 'ok' | 'close' | 'cancel';
57-
});
57+
});
58+
59+
/**
60+
* @deprecated Deprecated for consistence naming, to be removed in the next major update. Use
61+
* `ShowOptions` instead.
62+
*/
63+
export type OpenOptions = ShowOptions;
64+
65+
/**
66+
* @deprecated Deprecated for consistence naming, to be removed in the next major update. Use
67+
* `ShowOptionsButton` instead.
68+
*/
69+
export type OpenOptionsButton = ShowOptionsButton;

0 commit comments

Comments
 (0)