Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions types/w3c-sub-apps/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*
!**/*.d.ts
!**/*.d.cts
!**/*.d.mts
!**/*.d.*.ts
40 changes: 40 additions & 0 deletions types/w3c-sub-apps/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* @see https://wicg.github.io/sub-apps/
*/

/** Represents the https://w3c.github.io/manifest/#id-member */
export type ManifestId = string;

export interface SubAppsAddResponse {
/** Map of install paths as user provided to their corresponding ManifestId. */
installedApps: Record<string, ManifestId>;
/** Map of install paths as user provided to the error that occurred. */
failedApps: Record<string, DOMException>;
}

export interface SubAppsRemoveResponse {
/** List of successfully removed Sub Apps' ManifestIds. */
removedApps: ManifestId[];
/** Map of ManifestIds to the error that occurred. */
failedApps: Record<ManifestId, DOMException>;
}

export interface SubAppsListResult {
/** The name of the Sub App. */
appName: string;
}

declare global {
interface SubApps {
/** Installs one or more Sub Apps. */
add(install_paths: string[]): Promise<SubAppsAddResponse>;
/** Removes one or more Sub Apps. */
remove(manifest_ids: ManifestId[]): Promise<SubAppsRemoveResponse>;
/** Lists installed Sub Apps. */
list(): Promise<Record<ManifestId, SubAppsListResult>>;
}

interface Window {
readonly subApps: SubApps;
}
}
32 changes: 32 additions & 0 deletions types/w3c-sub-apps/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"private": true,
"nonNpm": true,
"nonNpmDescription": "Implementation of Isolated Web App (IWA) APIs resides in Chromium.",
"name": "@types/w3c-sub-apps",
"version": "0.0.9999",
"projects": [
"https://wicg.github.io/sub-apps/"
],
"devDependencies": {
"@types/web": "*",
"@types/w3c-sub-apps": "workspace:."
},
"owners": [
{
"name": "Vlad Krot",
"githubUsername": "vkrot-cell"
},
{
"name": "Edman Anjos",
"githubUsername": "edman"
},
{
"name": "Andrew Rayskiy",
"githubUsername": "GrapeGreen"
},
{
"name": "Simon Hangl",
"githubUsername": "shangl"
}
]
}
25 changes: 25 additions & 0 deletions types/w3c-sub-apps/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "node16",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"w3c-sub-apps": [
"./index.d.ts"
]
}
},
"files": [
"index.d.ts",
"w3c-sub-apps-tests.ts"
]
}
57 changes: 57 additions & 0 deletions types/w3c-sub-apps/w3c-sub-apps-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { ManifestId, SubAppsAddResponse, SubAppsListResult, SubAppsRemoveResponse } from "w3c-sub-apps";

async function testSubAppsApi() {
// --------------------------------------------------------------------------------
// Synchronous Type Definitions (Interfaces)
// --------------------------------------------------------------------------------

const manifestId: ManifestId = "some-id";
// $ExpectType string
manifestId;

const addResponse: SubAppsAddResponse = {
installedApps: { "/path": manifestId },
failedApps: { "/path2": new DOMException() },
};
// $ExpectType Record<string, string>
addResponse.installedApps;
// $ExpectType Record<string, DOMException>
addResponse.failedApps;

const removeResponse: SubAppsRemoveResponse = {
removedApps: [manifestId],
failedApps: { "/path2": new DOMException() },
};
// $ExpectType string[]
removeResponse.removedApps;
// $ExpectType Record<string, DOMException>
removeResponse.failedApps;

const listResult: SubAppsListResult = {
appName: "App 1",
};
// $ExpectType string
listResult.appName;

// --------------------------------------------------------------------------------
// SubApps (Window Augmentation)
// --------------------------------------------------------------------------------

if (window.subApps) {
const subApps = window.subApps;
// $ExpectType SubApps
subApps;

const addPromise = subApps.add(["/path1"]);
// $ExpectType Promise<SubAppsAddResponse>
addPromise;

const removePromise = subApps.remove([manifestId]);
// $ExpectType Promise<SubAppsRemoveResponse>
removePromise;

const listPromise = subApps.list();
// $ExpectType Promise<Record<string, SubAppsListResult>>
listPromise;
}
}