Skip to content

Instantly share code, notes, and snippets.

View ThomasKruegl's full-sized avatar

Thomas Krügl ThomasKruegl

View GitHub Profile
async function thisGetsCalled(): Promise<string> {
throw new Error("bla");
}
function convert(error: any) {
throw new Error("different");
}
async function main() {
// this is not working, error TS2322: Type 'string | void' is not assignable to type 'string'.
@ThomasKruegl
ThomasKruegl / winston_app_insights.ts
Last active February 28, 2018 15:24
Testing logging nested metadata objects in winston, auto collected to application insights
import * as util from "util";
const appInsights = require("applicationinsights");
appInsights.setup("instrumentationKey");
appInsights.start();
const winston = require("winston");
const testLogger1 = new winston.Logger();
const consoleTransport = new winston.transports.Console({
level: "info",
// how to type such?
var x= {}
x.foo = 27;
x.bar = foo+10;
x.as_str = x.foo + " " + x.bar;
return x;
interface X<T> {
foo: T;
bar: T | string;
function someMethod(f: () => void) {
f();
}
const myCallback = () => console.log("doing stuff…");
someMethod(myCallback);
val bar: Option[() => String] = Option(() => "five")
val matchResult: String = bar match {
case Some(a) => a()
case None => "None"
}
function throwing(): never {
throw new Error();
}
function throwingAgain(condition: boolean): never {
if (condition) {
throw new Error();
} else {
// solution: add return for this
throwing();
class MyError extends Error {
}
async function doSomething() {
return Promise.resolve({value: 5});
}
async function doSomethingElse(value: number): Promise<string> {
return Promise.reject(new Error("myMessage"));
}
export function buildRequestHandler(): RequestHandler {
return (externalRequest: Request, externalResponse: Response, next: NextFunction) => {
const errorHandler = (error: any) => {
if (externalResponse.headersSent) {
return next(error);
}
externalResponse.status(INTERNAL_SERVER_ERROR).json(createDefaultErrorBody(error));
};
const litegraph = require("litegraph.js").LiteGraph;
litegraph.debug = true;
class TickEVENT extends (litegraph.LGraphNode as { new(): any; }) {
public static title: string = "Event Tick";
public static desc: string = "";
constructor() {
super();
"use strict";
function asyncStuff() {
return new Promise((resolve, reject) => {
setTimeout(() => resolve("finished"), 2000);
});
}
function killedHandler() {
console.log("killedHandler called");
asyncStuff().then(console.log);
// process.exit(1);