This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function someMethod(f: () => void) { | |
f(); | |
} | |
const myCallback = () => console.log("doing stuff…"); | |
someMethod(myCallback); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val bar: Option[() => String] = Option(() => "five") | |
val matchResult: String = bar match { | |
case Some(a) => a() | |
case None => "None" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function throwing(): never { | |
throw new Error(); | |
} | |
function throwingAgain(condition: boolean): never { | |
if (condition) { | |
throw new Error(); | |
} else { | |
// solution: add return for this | |
throwing(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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); |
OlderNewer