Skip to content

Instantly share code, notes, and snippets.

View DanielRosenwasser's full-sized avatar

Daniel Rosenwasser DanielRosenwasser

View GitHub Profile
@DanielRosenwasser
DanielRosenwasser / Notes.md
Created March 16, 2018 07:46
Conditional Types Conversation 2018-01-03

[[Early thoughts around conditional types]]

Conditional Types

  • Currently have T extends Foo as a type operator that returns true or false.
    • Seems very strange as to what that actually means:
      declare function foo<T>(x: T, y: T extends string): void;
    • This function takes an x, and if x is a string, y must be true or otherwise false.
@DanielRosenwasser
DanielRosenwasser / use-api.ts
Last active May 15, 2017 20:51
Create and Print a Tree with the TypeScript API
import ts = require("typescript");
function makeFactorialFunction() {
const functionName = ts.createIdentifier("factorial");
const paramName = ts.createIdentifier("n");
const parameter = ts.createParameter(
/*decorators*/ undefined,
/*modifiers*/ undefined,
/*dotDotDotToken*/ undefined,
paramName);
declare function ava( run: ava.ContextualTest): void;
declare function ava(name: string, run: ava.ContextualTest): void;
declare function ava( run: ava.Macros<ava.ContextualTestContext>, ...args: Array<any>): void;
declare function ava(name: string, run: ava.Macros<ava.ContextualTestContext>, ...args: Array<any>): void;
declare namespace ava {
/**
* Misc Setup Types
*/
export type PromiseLike<R> = {
then<U>(
@DanielRosenwasser
DanielRosenwasser / axe-core.d.ts
Last active July 19, 2016 00:55 — forked from marcysutton/axe-core.d.ts
Typescript attempt #1
// Type definitions for axe-core 2.0.5
// Project: https://github.com/dequelabs/axe-core
// Definitions by: Marcy Sutton <https://github.com/marcysutton>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare const enum Tags {"wcag2a", "wcag2aa", "section508", "best-practice"}
declare const enum Reporter {"v1", "v2"}
interface ElementContext {
@DanielRosenwasser
DanielRosenwasser / literal-type-strategies-2016-01-21.md
Last active January 21, 2016 21:13
Which strategy do we take with literal types?

Motivation

Originally we used contextual types to decide when to infer a string literal type. If a string literal had a contextual type, we'd create a literal type for the string. That was the only change.

We ran into two basic problems:

  1. When you want to infer a string literal type for a variable, you always have to write a type annotation.
@DanielRosenwasser
DanielRosenwasser / typescript-services-diff-issue-6141.diff
Created December 18, 2015 01:35
Changeset for lint introductions on services.ts (TypeScript issue #6141)
diff --git a/src/services/services.ts b/src/services/services.ts
index a9dda54..8f90284 100644
--- a/src/services/services.ts
+++ b/src/services/services.ts
@@ -12,7 +12,7 @@
namespace ts {
/** The version of the language service API */
- export let servicesVersion = "0.4"
+ export const servicesVersion = "0.4";