Skip to content

Instantly share code, notes, and snippets.

@ChrisJamesC
Created September 23, 2016 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisJamesC/02b6d3394202e1fff8c6664d12cfbf5a to your computer and use it in GitHub Desktop.
Save ChrisJamesC/02b6d3394202e1fff8c6664d12cfbf5a to your computer and use it in GitHub Desktop.
Typescript 2.0.3 - Enzyme - Out of memory

This gist contains the minimum set of files I found necessary to reproduce an out of memory exception in Typescript 2.0.3.

On my computer, triggering a save on index.ts only once was sufficient to make the typescript compiler crash.

Here is the diagnostic on the first run:

> tsc --diagnostics index.ts

Files:               4
Lines:           21728
Nodes:          106235
Identifiers:     38755
Symbols:        809529
Types:          725193
Memory used:   798582K
I/O read:        0.00s
I/O write:       0.00s
Parse time:      0.22s
Bind time:       0.16s
Check time:      7.88s
Emit time:       0.02s
Total time:      8.28s
// Inspired by the Type definitions for Enzyme v2.4.1
// Project: https://github.com/airbnb/enzyme
// Definitions by: Marian Palkus <https://github.com/MarianPalkus>, Cap3 <http://www.cap3.de>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { StatelessComponent, HTMLAttributes } from "react";
type ReactElement<T> = any;
export type EnzymeSelector = string | StatelessComponent<any> | { [key: string]: any };
export type EnzymePropSelector = { [key: string]: any };
interface CommonWrapper<P, S> {
find<P2>(statelessComponent: StatelessComponent<P2>): CommonWrapper<P2, {}>;
find(selector: string): CommonWrapper<HTMLAttributes<{}>, any>;
findWhere(predicate: (wrapper: CommonWrapper<any, any>) => boolean): CommonWrapper<any, any>;
filter<P2>(statelessComponent: StatelessComponent<P2>): CommonWrapper<P2, {}>;
filter(selector: string): CommonWrapper<HTMLAttributes<{}>, any>;
children<P2>(statelessComponent: StatelessComponent<P2>): CommonWrapper<P2, {}>;
children(selector: string): CommonWrapper<HTMLAttributes<{}>, any>;
children(): CommonWrapper<any, any>;
childAt(index: number): CommonWrapper<any, any>;
childAt<P2, S2>(index: number): CommonWrapper<P2, S2>;
parents<P2>(statelessComponent: StatelessComponent<P2>): CommonWrapper<P2, {}>;
parents(selector: string): CommonWrapper<HTMLAttributes<{}>, any>;
parents(): CommonWrapper<any, any>;
parent(): CommonWrapper<any, any>;
closest<P2>(statelessComponent: StatelessComponent<P2>): CommonWrapper<P2, {}>;
closest(selector: string): CommonWrapper<HTMLAttributes<{}>, any>;
text(): string;
html(): string;
get(index: number): ReactElement<any>;
at(index: number): this;
first(): this;
last(): this;
state(key?: string): any;
state<T>(key?: string): T;
context(key?: string): any;
context<T>(key?: string): T;
props(): P;
prop(key: string): any;
prop<T>(key: string): T;
key(): string;
simulate(event: string, ...args: any[]): this;
setState(state: S): this;
setProps(props: P): this;
setContext(context: Object): this;
update(): this;
debug(): string;
type(): string | Function;
name(): string;
forEach(fn: (wrapper: this) => any): this;
map<V>(fn: (wrapper: this) => V): V[];
reduce<R>(fn: (prevVal: R, wrapper: this, index: number) => R, initialValue?: R): R[];
reduceRight<R>(fn: (prevVal: R, wrapper: this, index: number) => R, initialValue?: R): R[];
some(selector: EnzymeSelector): boolean;
someWhere(fn: (wrapper: this) => boolean): boolean;
every(selector: EnzymeSelector): boolean;
everyWhere(fn: (wrapper: this) => boolean): boolean;
length: number;
}
export interface ShallowWrapper<P, S> extends CommonWrapper<P, S> {
shallow(): ShallowWrapper<P, S>;
unmount(): ShallowWrapper<any, any>;
find<P2>(statelessComponent: (props: P2) => JSX.Element): ShallowWrapper<P2, {}>;
find(selector: string): ShallowWrapper<HTMLAttributes<{}>, any>;
filter<P2>(statelessComponent: StatelessComponent<P2>): ShallowWrapper<P2, {}>;
filter(selector: string): ShallowWrapper<HTMLAttributes<{}>, any>;
findWhere(predicate: (wrapper: CommonWrapper<any, any>) => boolean): ShallowWrapper<any, any>;
children<P2>(statelessComponent: StatelessComponent<P2>): ShallowWrapper<P2, {}>;
children(selector: string): ShallowWrapper<HTMLAttributes<{}>, any>;
children(): ShallowWrapper<any, any>;
childAt(index: number): ShallowWrapper<any, any>;
childAt<P2, S2>(index: number): ShallowWrapper<P2, S2>;
parents<P2>(statelessComponent: StatelessComponent<P2>): ShallowWrapper<P2, {}>;
parents(selector: string): ShallowWrapper<HTMLAttributes<{}>, any>;
parents(): ShallowWrapper<any, any>;
closest<P2>(statelessComponent: StatelessComponent<P2>): ShallowWrapper<P2, {}>;
closest(selector: string): ShallowWrapper<HTMLAttributes<{}>, any>;
parent(): ShallowWrapper<any, any>;
isEmptyRender(): boolean;
}
export interface ReactWrapper<P, S> extends CommonWrapper<P, S> {
unmount(): ReactWrapper<any, any>;
mount(): ReactWrapper<any, any>;
ref(refName: string): ReactWrapper<any, any>;
ref<P2, S2>(refName: string): ReactWrapper<P2, S2>;
detach(): void;
find<P2>(statelessComponent: (props: P2) => JSX.Element): ReactWrapper<P2, {}>;
find(selector: string): ReactWrapper<HTMLAttributes<{}>, any>;
findWhere(predicate: (wrapper: CommonWrapper<any, any>) => boolean): ReactWrapper<any, any>;
filter<P2>(statelessComponent: StatelessComponent<P2>): ReactWrapper<P2, {}>;
filter(selector: string): ReactWrapper<HTMLAttributes<{}>, any>;
children<P2>(statelessComponent: StatelessComponent<P2>): ReactWrapper<P2, {}>;
children(selector: string): ReactWrapper<HTMLAttributes<{}>, any>;
children(): ReactWrapper<any, any>;
childAt(index: number): ReactWrapper<any, any>;
childAt<P2, S2>(index: number): ReactWrapper<P2, S2>;
parents<P2>(statelessComponent: StatelessComponent<P2>): ReactWrapper<P2, {}>;
parents(selector: string): ReactWrapper<HTMLAttributes<{}>, any>;
parents(): ReactWrapper<any, any>;
closest<P2>(statelessComponent: StatelessComponent<P2>): ReactWrapper<P2, {}>;
closest(selector: string): ReactWrapper<HTMLAttributes<{}>, any>;
parent(): ReactWrapper<any, any>;
isEmptyRender(): boolean;
}
/// <reference path="enzyme.d.ts" />
{
"name": "typescript_bug",
"version": "1.0.0",
"description": "",
"scripts": {
"start": "tsc --diagnostics -w index.ts"
},
"author": "Christopher Chiche",
"license": "ISC",
"devDependencies": {
"@types/react": "^0.14.36",
"typescript": "^2.0.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment