Skip to content

Instantly share code, notes, and snippets.

View NaridaL's full-sized avatar

Adrian Leonhard NaridaL

  • Microsoft
  • Dublin, Ireland
View GitHub Profile
// A.ts
abstract class A {
public static create(t: boolean) {
//noinspection TsLint
const b = new D();
return t ? new B() : new C();
}
abstract foo(): string
// A.ts
abstract class A {
public static create(t: boolean) {
//noinspection TsLint
const b = new D();
return t ? new B() : new C();
}
abstract foo(): string
declare module 'express-session' {
import express = require('express');
import node = require('events');
function session(options?: session.SessionOptions): express.RequestHandler;
namespace session {
export interface SessionOptions {
secret: string;
name?: string;
export type KeysToTrue<T> = {
[P in Key<T>]: true;
}
export type Key<T> = keyof T
export type Mapping<T, S> = {
[P in Key<T>]: S
}
///<reference path="NLA.ts"/>
class CustomSet<T extends Equalable> implements Set<T> {
[Symbol.toStringTag]:'Set' = 'Set'
forEach(callbackfn: (value: T, index: T, set: Set<T>)=>void, thisArg?: any): void {
for (const value of this.entries()) {
callbackfn.call(thisArg, value, value, this)
///<reference path="NLA.ts"/>
///<reference path="NLA.ts"/>
/**
* Java style map.
*/
class CustomMap<K extends { hashCode(): int, equals(x: any): boolean, hashCodes?(): int[], like(x: any): boolean }, V> implements Map<K, V> {
[Symbol.toStringTag]: 'Map' = 'Map'
toString() {
// see also https://www.npmjs.com/package/subtractiontype.ts
// for literal unions
type Sub0<
O extends string,
D extends string,
> = {[K in O]: (Record<D, never> & Record<string, K>)[K]}
type Sub<
@NaridaL
NaridaL / tsfaq.md
Last active November 9, 2017 19:25

Pseudo-Variadic arguments aka How do I change the return type of a function?

Until microsoft/TypeScript#5453 is implemented, you'll need to create multiple overloads, one for each number of arguments. For example, this is the type definition of a function which takes a function and returns a function with the same arguments but the result wrapped in a Promise.

declare function wrapPromise<R>(f: () => R): () => Promise<R> 
declare function wrapPromise<A1, R>(f: (a1: A1) => R): (a1: A1) => Promise<R>
declare function wrapPromise<A1, A2, R>(f: (a1: A1, a2: A2) => R): (a1: A1, a2: A2) => Promise<R>
declare function wrapPromise<A1, A2, A3, R>(f: (a1: A1, a2: A2, a3: A3) => R): (a1: A1, a2: A2, a3: A3) => Promise<R>
declare function wrapPromise<A1, A2, A3, A4, R>(f: (a1: A1, a2: A2, a3: A3, a4: A4) => R): (a1: A1, a2: A2, a3: A3, a4: A4) => Promise<R>
// etc. 8 arguments should be enough for everyone :-P
declare module 'r-script' {
interface R {
data(...args: any[]): this
call(callback: (err: any, d: any) => void): void
call(options: R.Options, callback: (err: any, d: any) => void): void
callSync(options: R.Options): any
}
namespace R {
interface Options {
dataframe?: 'rows' | 'colums' | 'values'
// Type definitions for Electron 9.9.9
// Project: http://electron.atom.io/
// Definitions by: The Electron Team <https://github.com/electron/electron>
// Definitions: https://github.com/electron/electron-typescript-definitions
/// <reference types="node" />
type GlobalEvent = Event;
/** @deprecated */