Skip to content

Commit

Permalink
TW: add type for prompt() being async in desktop app
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Jan 20, 2025
1 parent 390dad5 commit 9be24ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/test-scratch-vm-tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,9 @@ target.extensionStorage['stretch'] = [
}
];
vm.runtime.extensionStorage['a'] = 'b';

const promptResult = prompt('what is your name');
promptResult as Promise<string>;
promptResult as Promise<null>;
promptResult as string;
promptResult as null;
5 changes: 5 additions & 0 deletions types/scratch-vm-extension.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
* reference error, not return undefined (TypeScript does not let us type that unfortunately)
*/
declare const scaffolding: unknown | undefined;
/**
* In desktop app, prompt() returns a Promise. Thus you should always do `await prompt(...)` which
* will work in all environments.
*/
declare function prompt(message?: string, _default?: string): string | null | Promise<string | null>;

declare namespace Scratch {
// TW
Expand Down

0 comments on commit 9be24ef

Please sign in to comment.