Skip to content
This repository was archived by the owner on Mar 5, 2021. It is now read-only.

Replace <Type>x with x as Type (fixes #21) #30

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 2 additions & 2 deletions SupCore/Data/Base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function getRuleViolation(value: any, rule: Rule, create = false): Violat
case "enum": {
if (typeof value !== "string") return { message: "Expected string for enum" };

let items = <string[]>rule.items;
let items = rule.items as string[];
if (items.indexOf(value) === -1) return { message: `Invalid enum value: ${value}` };
} break;

Expand Down Expand Up @@ -130,7 +130,7 @@ export function getRuleViolation(value: any, rule: Rule, create = false): Violat
if (rule.items != null) {
for (let index = 0; index < value.length; index++) {
let item: any = value[index];
let violation = getRuleViolation(item, <Rule>rule.items, true);
let violation = getRuleViolation(item, rule.items as Rule, true);
if (violation != null) {
let violationPath = (violation.path != null) ? `[${index}].${violation.path}` : `[${index}]`;
return { message: violation.message, path: violationPath };
Expand Down
2 changes: 1 addition & 1 deletion SupCore/Data/Entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class Entries extends SupData.Base.TreeById {
}

remove(id: string, callback: (err: string) => any) {
let node = <EntryNode>this.byId[id];
let node = this.byId[id] as EntryNode;
if (node == null) { callback(`Invalid node id: ${id}`); return; }
if (node.type == null && node.children.length !== 0) { callback("The folder must be empty"); return; }

Expand Down
4 changes: 2 additions & 2 deletions client/src/dialogs/CreateOrEditProjectDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default class CreateOrEditProjectDialog extends SupClient.dialogs.BaseDia
// Description
this.descriptionInputElt = document.createElement("textarea");
this.descriptionInputElt.style.flex = "1";
(<any>this.descriptionInputElt.style).resize = "none";
(this.descriptionInputElt.style as any).resize = "none";
this.descriptionInputElt.placeholder = SupClient.i18n.t("hub:newProject.descriptionPlaceholder");
this.descriptionInputElt.addEventListener("keypress", this.onFieldKeyDown);
textContainerElt.appendChild(this.descriptionInputElt);
Expand Down Expand Up @@ -247,7 +247,7 @@ export default class CreateOrEditProjectDialog extends SupClient.dialogs.BaseDia
} else {
this.iconFile = this.iconInputElt.files[0];
let reader = new FileReader();
reader.addEventListener("load", (event) => { this.iconElt.src = (<any>event.target).result; });
reader.addEventListener("load", (event) => { this.iconElt.src = (event.target as any).result; });
reader.readAsDataURL(this.iconFile);
}
};
Expand Down
80 changes: 40 additions & 40 deletions client/src/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function start() {

// Development mode
if (localStorage.getItem("superpowers-dev-mode") != null) {
let projectManagementDiv = <HTMLDivElement>document.querySelector(".project-management");
let projectManagementDiv = document.querySelector(".project-management") as HTMLDivElement;
projectManagementDiv.style.backgroundColor = "#37d";

// According to http://stackoverflow.com/a/12747364/915914, window.onerror
Expand Down Expand Up @@ -96,9 +96,9 @@ function start() {
document.querySelector(".project-buttons .stop").addEventListener("click", () => { stopProject(); });

if (!SupClient.isApp) {
(<HTMLButtonElement>document.querySelector(".project-buttons .publish")).title = SupClient.i18n.t("project:header.publishDisabled");
(<HTMLButtonElement>document.querySelector(".project-buttons .debug")).hidden = true;
(<HTMLButtonElement>document.querySelector(".project-buttons .stop")).hidden = true;
(document.querySelector(".project-buttons .publish") as HTMLButtonElement).title = SupClient.i18n.t("project:header.publishDisabled");
(document.querySelector(".project-buttons .debug") as HTMLButtonElement).hidden = true;
(document.querySelector(".project-buttons .stop") as HTMLButtonElement).hidden = true;
}

// Entries tree view
Expand Down Expand Up @@ -136,7 +136,7 @@ function start() {
});

// Global controls
let toggleNotificationsButton = <HTMLButtonElement>document.querySelector(".top .controls button.toggle-notifications");
let toggleNotificationsButton = document.querySelector(".top .controls button.toggle-notifications") as HTMLButtonElement;
toggleNotificationsButton.addEventListener("click", onClickToggleNotifications);

if (localStorage.getItem("superpowers-disable-notifications") != null) {
Expand All @@ -148,8 +148,8 @@ function start() {
}

// Panes and tools
ui.panesElt = <HTMLDivElement>document.querySelector(".main .panes");
ui.toolsElt = <HTMLUListElement>document.querySelector(".sidebar .tools ul");
ui.panesElt = document.querySelector(".main .panes") as HTMLDivElement;
ui.toolsElt = document.querySelector(".sidebar .tools ul") as HTMLUListElement;

// Messaging
window.addEventListener("message", onMessage);
Expand Down Expand Up @@ -293,14 +293,14 @@ function onDisconnected() {
ui.entriesTreeView.treeRoot.innerHTML = "";
updateSelectedEntry();

(<HTMLButtonElement>document.querySelector(".project-buttons .run")).disabled = true;
(<HTMLButtonElement>document.querySelector(".project-buttons .debug")).disabled = true;
(<HTMLButtonElement>document.querySelector(".project-buttons .stop")).disabled = true;
(<HTMLButtonElement>document.querySelector(".project-buttons .publish")).disabled = true;
(<HTMLButtonElement>document.querySelector(".entries-buttons .new-asset")).disabled = true;
(<HTMLButtonElement>document.querySelector(".entries-buttons .new-folder")).disabled = true;
(<HTMLButtonElement>document.querySelector(".entries-buttons .search")).disabled = true;
(<HTMLDivElement>document.querySelector(".connecting")).hidden = false;
(document.querySelector(".project-buttons .run") as HTMLButtonElement).disabled = true;
(document.querySelector(".project-buttons .debug") as HTMLButtonElement).disabled = true;
(document.querySelector(".project-buttons .stop") as HTMLButtonElement).disabled = true;
(document.querySelector(".project-buttons .publish") as HTMLButtonElement).disabled = true;
(document.querySelector(".entries-buttons .new-asset") as HTMLButtonElement).disabled = true;
(document.querySelector(".entries-buttons .new-folder") as HTMLButtonElement).disabled = true;
(document.querySelector(".entries-buttons .search") as HTMLButtonElement).disabled = true;
(document.querySelector(".connecting") as HTMLDivElement).hidden = false;
}

function onWelcome(clientId: number, config: { buildPort: number; systemName: string; }) {
Expand Down Expand Up @@ -336,14 +336,14 @@ function onEntriesReceived(err: string, entries: SupCore.Data.EntryNode[]) {
ui.entriesTreeView.clearSelection();
ui.entriesTreeView.treeRoot.innerHTML = "";

(<HTMLDivElement>document.querySelector(".connecting")).hidden = true;
(document.querySelector(".connecting") as HTMLDivElement).hidden = true;

if (SupClient.isApp) (<HTMLButtonElement>document.querySelector(".project-buttons .publish")).disabled = false;
(<HTMLButtonElement>document.querySelector(".project-buttons .run")).disabled = false;
(<HTMLButtonElement>document.querySelector(".project-buttons .debug")).disabled = false;
(<HTMLButtonElement>document.querySelector(".entries-buttons .new-asset")).disabled = false;
(<HTMLButtonElement>document.querySelector(".entries-buttons .new-folder")).disabled = false;
(<HTMLButtonElement>document.querySelector(".entries-buttons .search")).disabled = false;
if (SupClient.isApp) (document.querySelector(".project-buttons .publish") as HTMLButtonElement).disabled = false;
(document.querySelector(".project-buttons .run") as HTMLButtonElement).disabled = false;
(document.querySelector(".project-buttons .debug") as HTMLButtonElement).disabled = false;
(document.querySelector(".entries-buttons .new-asset") as HTMLButtonElement).disabled = false;
(document.querySelector(".entries-buttons .new-folder") as HTMLButtonElement).disabled = false;
(document.querySelector(".entries-buttons .search") as HTMLButtonElement).disabled = false;

function walk(entry: SupCore.Data.EntryNode, parentEntry: SupCore.Data.EntryNode, parentElt: HTMLLIElement) {
let liElt = createEntryElement(entry);
Expand Down Expand Up @@ -402,11 +402,11 @@ function onEntryAddedAck(err: string, id: string) {
function onEntryMoved(id: string, parentId: string, index: number) {
data.entries.client_move(id, parentId, index);

let entryElt = <HTMLLIElement>ui.entriesTreeView.treeRoot.querySelector(`[data-id='${id}']`);
let entryElt = ui.entriesTreeView.treeRoot.querySelector(`[data-id='${id}']`) as HTMLLIElement;

let oldParentId: string = entryElt.dataset["parentId"];
if (oldParentId != null) {
let oldParentElt = <HTMLLIElement>ui.entriesTreeView.treeRoot.querySelector(`[data-id='${oldParentId}']`);
let oldParentElt = ui.entriesTreeView.treeRoot.querySelector(`[data-id='${oldParentId}']`) as HTMLLIElement;
let parentEntry = data.entries.byId[oldParentId];
let childrenElt = oldParentElt.querySelector("span.children");
childrenElt.textContent = `(${parentEntry.children.length})`;
Expand Down Expand Up @@ -447,7 +447,7 @@ function onEntryTrashed(id: string) {

let oldParentId: string = entryElt.dataset["parentId"];
if (oldParentId != null) {
let oldParentElt = <HTMLLIElement>ui.entriesTreeView.treeRoot.querySelector(`[data-id='${oldParentId}']`);
let oldParentElt = ui.entriesTreeView.treeRoot.querySelector(`[data-id='${oldParentId}']`) as HTMLLIElement;
let parentEntry = data.entries.byId[oldParentId];
let childrenElt = oldParentElt.querySelector("span.children");
childrenElt.textContent = `(${parentEntry.children.length})`;
Expand Down Expand Up @@ -645,7 +645,7 @@ function onEntryDrop(dropInfo: any, orderedNodes: any) {
function updateSelectedEntry() {
let allButtons = document.querySelectorAll(".entries-buttons button.edit");
for (let index = 0; index < allButtons.length; index++) {
let button = <HTMLButtonElement>allButtons.item(index);
let button = allButtons.item(index) as HTMLButtonElement;
let disabled = (ui.entriesTreeView.selectedNodes.length === 0 ||
(button.classList.contains("single") && ui.entriesTreeView.selectedNodes.length !== 1) ||
(button.classList.contains("asset-only") && ui.entriesTreeView.selectedNodes[0].classList.contains("group")));
Expand All @@ -670,7 +670,7 @@ function onMessage(event: any) {
}

function onWindowDevError() {
let projectManagementDiv = <HTMLDivElement>document.querySelector(".project-management");
let projectManagementDiv = document.querySelector(".project-management") as HTMLDivElement;
projectManagementDiv.style.backgroundColor = "#c42";
return false;
}
Expand All @@ -685,7 +685,7 @@ function onMessageChat(message: string) {

function doNotification() {
let title = SupClient.i18n.t("project:header.notifications.new", { projectName: data.manifest.pub.name });
let notification = new (<any>window).Notification(title, { icon: "/images/icon.png", body: message });
let notification = new (window as any).Notification(title, { icon: "/images/icon.png", body: message });

let closeTimeoutId = setTimeout(() => { notification.close(); }, 5000);

Expand All @@ -697,11 +697,11 @@ function onMessageChat(message: string) {
});
}

if ((<any>window).Notification.permission === "granted") doNotification();
else if ((<any>window).Notification.permission !== "denied") {
(<any>window).Notification.requestPermission((status: string) => {
(<any>window).Notification.permission = status;
if ((<any>window).Notification.permission === "granted") doNotification();
if ((window as any).Notification.permission === "granted") doNotification();
else if ((window as any).Notification.permission !== "denied") {
(window as any).Notification.requestPermission((status: string) => {
(window as any).Notification.permission = status;
if ((window as any).Notification.permission === "granted") doNotification();
});
}
}
Expand Down Expand Up @@ -753,7 +753,7 @@ function openEntry(id: string, state?: {[name: string]: any}) {
if (entry.type == null) { ui.entriesTreeView.selectedNodes[0].classList.toggle("collapsed"); return; }

let tab = ui.tabStrip.tabsRoot.querySelector(`li[data-asset-id='${id}']`);
let iframe = <HTMLIFrameElement>ui.panesElt.querySelector(`iframe[data-asset-id='${id}']`);
let iframe = ui.panesElt.querySelector(`iframe[data-asset-id='${id}']`) as HTMLIFrameElement;

if (tab == null) {
tab = createAssetTabElement(entry);
Expand All @@ -772,7 +772,7 @@ function openEntry(id: string, state?: {[name: string]: any}) {

function openTool(name: string, state?: {[name: string]: any}) {
let tab = ui.tabStrip.tabsRoot.querySelector(`li[data-pane='${name}']`);
let iframe = <HTMLIFrameElement>ui.panesElt.querySelector(`iframe[data-name='${name}']`);
let iframe = ui.panesElt.querySelector(`iframe[data-name='${name}']`) as HTMLIFrameElement;

if (tab == null) {
let tool = data.toolsByName[name];
Expand Down Expand Up @@ -1031,7 +1031,7 @@ function onTabActivate(tabElement: any) {
if (activeTab != null) {
activeTab.classList.remove("active");

let activeIframe = (<HTMLIFrameElement>ui.panesElt.querySelector("iframe.active"));
let activeIframe = (ui.panesElt.querySelector("iframe.active") as HTMLIFrameElement);
activeIframe.contentWindow.postMessage({ type: "deactivate" }, window.location.origin);
activeIframe.classList.remove("active");
}
Expand All @@ -1041,8 +1041,8 @@ function onTabActivate(tabElement: any) {

let assetId = tabElement.dataset["assetId"];
let tabIframe: HTMLIFrameElement;
if (assetId != null) tabIframe = <HTMLIFrameElement>ui.panesElt.querySelector(`iframe[data-asset-id='${assetId}']`);
else tabIframe = <HTMLIFrameElement>ui.panesElt.querySelector(`iframe[data-name='${tabElement.dataset.pane}']`);
if (assetId != null) tabIframe = ui.panesElt.querySelector(`iframe[data-asset-id='${assetId}']`) as HTMLIFrameElement;
else tabIframe = ui.panesElt.querySelector(`iframe[data-name='${tabElement.dataset.pane}']`) as HTMLIFrameElement;

tabIframe.classList.add("active");
tabIframe.contentWindow.focus();
Expand All @@ -1052,12 +1052,12 @@ function onTabActivate(tabElement: any) {
function onTabClose(tabElement: HTMLLIElement) {
let assetId = tabElement.dataset["assetId"];
let frameElt: HTMLIFrameElement;
if (assetId != null) frameElt = <HTMLIFrameElement>ui.panesElt.querySelector(`iframe[data-asset-id='${assetId}']`);
if (assetId != null) frameElt = ui.panesElt.querySelector(`iframe[data-asset-id='${assetId}']`) as HTMLIFrameElement;
else {
let toolName = tabElement.dataset["pane"];
if (toolName === "main") return;

frameElt = <HTMLIFrameElement>ui.panesElt.querySelector(`iframe[data-name='${toolName}']`);
frameElt = ui.panesElt.querySelector(`iframe[data-name='${toolName}']`) as HTMLIFrameElement;
}

if (tabElement.classList.contains("active")) {
Expand Down
6 changes: 3 additions & 3 deletions launcher/src/myServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ let childProcess = nodeRequire("child_process");

let myServerElt = document.querySelector(".my-server");

let myServerTextarea = <HTMLTextAreaElement>myServerElt.querySelector("textarea");
let myServerTextarea = myServerElt.querySelector("textarea") as HTMLTextAreaElement;
export let serverProcess: dummy_childProcess.ChildProcess = null;

let autoStartServerCheckbox = <HTMLInputElement>document.getElementById("auto-start-server");
let autoStartServerCheckbox = document.getElementById("auto-start-server") as HTMLInputElement;
autoStartServerCheckbox.checked = config.autoStartServer;

autoStartServerCheckbox.addEventListener("change", (event) => {
config.autoStartServer = autoStartServerCheckbox.checked;
});

let startStopServerButton = <HTMLButtonElement>myServerElt.querySelector("button.start-stop-server");
let startStopServerButton = myServerElt.querySelector("button.start-stop-server") as HTMLButtonElement;
startStopServerButton.addEventListener("click", () => {
if (serverProcess != null) {
startStopServerButton.textContent = "Start";
Expand Down
4 changes: 2 additions & 2 deletions launcher/src/panes/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export {};
let electron: GitHubElectron.Electron = nodeRequire("electron");

document.querySelector(".panes .community").addEventListener("click", (event) => {
if ((<Element>event.target).tagName !== "A") return;
if ((event.target as Element).tagName !== "A") return;

event.preventDefault();
electron.shell.openExternal((<HTMLAnchorElement>event.target).href);
electron.shell.openExternal((event.target as HTMLAnchorElement).href);
});
18 changes: 9 additions & 9 deletions launcher/src/panes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import "./settings";
import "./community";

// Panes
let paneButtonsContainer = <HTMLDivElement>document.querySelector(".pane-buttons");
let panesContainer = <HTMLDivElement>document.querySelector(".panes");
let paneButtonsContainer = document.querySelector(".pane-buttons") as HTMLDivElement;
let panesContainer = document.querySelector(".panes") as HTMLDivElement;

for (let i = 0; i < paneButtonsContainer.children.length; i++) {
((button: HTMLButtonElement, i: number) => {
button.addEventListener("click", (event) => {
(<HTMLButtonElement>paneButtonsContainer.querySelector("button.active")).classList.remove("active");
(<HTMLDivElement>panesContainer.querySelector(".active")).classList.remove("active");
(<HTMLButtonElement>event.target).classList.add("active");
(<HTMLDivElement>panesContainer.children[i]).classList.add("active");
(paneButtonsContainer.querySelector("button.active") as HTMLButtonElement).classList.remove("active");
(panesContainer.querySelector(".active") as HTMLDivElement).classList.remove("active");
(event.target as HTMLButtonElement).classList.add("active");
(panesContainer.children[i] as HTMLDivElement).classList.add("active");
});
})(<HTMLButtonElement>paneButtonsContainer.children[i], i);
})(paneButtonsContainer.children[i] as HTMLButtonElement, i);
}

(<HTMLButtonElement>paneButtonsContainer.children[0]).classList.add("active");
(<HTMLDivElement>panesContainer.children[0]).classList.add("active");
(paneButtonsContainer.children[0] as HTMLButtonElement).classList.add("active");
(panesContainer.children[0] as HTMLDivElement).classList.add("active");
4 changes: 2 additions & 2 deletions launcher/src/panes/servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ function start() {
}

function createServerElement(entry: { name: string; address: string; }) {
let liElt = <HTMLLIElement>document.createElement("li");
let liElt = document.createElement("li") as HTMLLIElement;
liElt.dataset["name"] = entry.name;
liElt.dataset["address"] = entry.address;

let nameSpan = <HTMLSpanElement>document.createElement("span");
let nameSpan = document.createElement("span") as HTMLSpanElement;
nameSpan.className = "name";
nameSpan.textContent = entry.name;
liElt.appendChild(nameSpan);
Expand Down
8 changes: 4 additions & 4 deletions launcher/src/panes/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ if (fs.existsSync(serverPaths.config)) {
_.merge(config, userConfig);
}

let mainPortInput = <HTMLInputElement>document.querySelector("input.main-server-port");
let buildPortInput = <HTMLInputElement>document.querySelector("input.build-server-port");
let passwordInput = <HTMLInputElement>document.querySelector("input.server-password");
let maxRecentBuildsInput = <HTMLInputElement>document.querySelector("input.max-recent-builds");
let mainPortInput = document.querySelector("input.main-server-port") as HTMLInputElement;
let buildPortInput = document.querySelector("input.build-server-port") as HTMLInputElement;
let passwordInput = document.querySelector("input.server-password") as HTMLInputElement;
let maxRecentBuildsInput = document.querySelector("input.max-recent-builds") as HTMLInputElement;

mainPortInput.value = config.mainPort.toString();
buildPortInput.value = config.buildPort.toString();
Expand Down
Loading