Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#69370 [@types/ysdk] Add types for player p…
Browse files Browse the repository at this point in the history
…aying status api and more tests by @koteelok
  • Loading branch information
koteelok authored Apr 17, 2024
1 parent 895d2be commit 235f5ec
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 50 deletions.
1 change: 1 addition & 0 deletions types/ysdk/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export interface Player {
getUniqueID(): string;
getName(): string;
getPhoto(size: "small" | "medium" | "large"): string;
getPayingStatus(): "paying" | "partially_paying" | "not_paying" | "unknown";
getIDsPerGame(): Promise<Array<{ appID: number; userID: string }>>;
getMode(): "lite" | "";
getData<T extends string>(keys?: Readonly<T[]>): Promise<Partial<Record<T, Serializable>>>;
Expand Down
132 changes: 82 additions & 50 deletions types/ysdk/ysdk-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,56 +67,6 @@ async function Payments() {
purchase.signature;
}

async function Player() {
// $ExpectType SDK
const ysdk = await YaGames.init();

// $ExpectType Promise<void>
ysdk.auth.openAuthDialog();

// $ExpectType Promise<Player>
ysdk.getPlayer();

// $ExpectType Signed<Player>
const player = await ysdk.getPlayer({ signed: true });

// $ExpectType string
player.signature;

// $ExpectType string
player.getUniqueID();

// $ExpectType string
player.getName();

// $ExpectType string
player.getPhoto("small");

// $ExpectType string
player.getPhoto("medium");

// $ExpectType string
player.getPhoto("large");

// $ExpectType Promise<{ appID: number; userID: string; }[]>
player.getIDsPerGame();

// $ExpectType Promise<Partial<Record<string, Serializable>>>
player.getData();

// $ExpectType Promise<Partial<Record<"id" | "nigger", Serializable>>>
player.getData(["id", "nigger"]);

// $ExpectType Promise<Partial<Record<string, number>>>
player.getStats();

// $ExpectType Promise<Partial<Record<"test", number>>>
player.getStats(["test"]);

// $ExpectType Promise<IncrementedStats<{ test: number; }>>
player.incrementStats({ test: 123 });
}

async function Leaderboards() {
// $ExpectType SDK
const ysdk = await YaGames.init();
Expand Down Expand Up @@ -248,6 +198,68 @@ async function Leaderboards() {
leaderboards.setLeaderboardScore("top", 123, "test");
}

async function Player() {
// $ExpectType SDK
const ysdk = await YaGames.init();

// $ExpectType Promise<void>
ysdk.auth.openAuthDialog();

// $ExpectType Promise<Player>
ysdk.getPlayer();

// $ExpectType Signed<Player>
const player = await ysdk.getPlayer({ signed: true });

// $ExpectType "" | "lite"
player.getMode();

// $ExpectType "paying" | "partially_paying" | "not_paying" | "unknown"
player.getPayingStatus();

// $ExpectType string
player.signature;

// $ExpectType string
player.getUniqueID();

// $ExpectType string
player.getName();

// $ExpectType string
player.getPhoto("small");

// $ExpectType string
player.getPhoto("medium");

// $ExpectType string
player.getPhoto("large");

// $ExpectType Promise<{ appID: number; userID: string; }[]>
player.getIDsPerGame();

// $ExpectType Promise<Partial<Record<string, Serializable>>>
player.getData();

// $ExpectType Promise<Partial<Record<"id" | "name", Serializable>>>
player.getData(["id", "name"]);

// $ExpectType Promise<void>
player.setData({ test: "test" });

// $ExpectType Promise<Partial<Record<string, number>>>
player.getStats();

// $ExpectType Promise<Partial<Record<"test", number>>>
player.getStats(["test"]);

// $ExpectType Promise<IncrementedStats<{ test: number; }>>
player.incrementStats({ test: 123 });

// $ExpectType Promise<void>
player.setStats({ test: 123 });
}

async function Misc() {
// $ExpectType SDK
const ysdk = await YaGames.init();
Expand Down Expand Up @@ -320,4 +332,24 @@ async function Misc() {

// $ExpectType Promise<void>
ysdk.screen.fullscreen.exit();

// $ExpectType Promise<Storage>
ysdk.getStorage();

// $ExpectType Promise<Record<string, string>>
ysdk.getFlags({
clientFeatures: [{
name: "feature-name",
value: "feature-value",
}],
defaultFlags: {
"test-flag": "default-value",
},
});

// $ExpectType "EXIT"
ysdk.EVENTS.EXIT;

// $ExpectType "HISTORY_BACK"
ysdk.EVENTS.HISTORY_BACK;
}

0 comments on commit 235f5ec

Please sign in to comment.