-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TSC crashes on <30 line project #17036
Comments
Changing interface MonadNone<T> {
ap<U>(option: Some<(value: T) => U>): None<U>
chain<U>(f: (value: T) => Some<U>): None<T>
chain<U>(f: (value: T) => None<U>): None<T>
}
interface MonadSome<T> {
ap<U>(option: Some<(value: T) => U>): Some<U>
chain<U>(f: (value: T) => Some<U>): Some<U>
chain<U>(f: (value: T) => None<U>): None<T>
}
interface None<T> extends MonadNone<T> {
flatMap<U>(f: (value: T) => Some<U>): None<T>
flatMap<U>(f: (value: T) => None<U>): None<T>
}
interface Some<T> extends MonadSome<T> {
flatMap<U>(f: (value: T) => Some<U>): Some<U>
flatMap<U>(f: (value: T) => None<U>): None<T>
}
export type Option<T> = Some<T> | None<T>
export function None<T>(): None<T> {}
export function Some<T>(value: T): Option<T> {}
export let Option = <T>(value: T | null) => {
if (value == null) {
return None<T>()
}
return Some(value)
} This problem is probably caused by caching. Anonymous object type will not be cached, so some recursive signature like |
This seems like a big problem. TypeScript either needs to enforce a preferred type declaration scheme or support all type declarations equally. It's not enough for the official response to be, "just use interfaces". That makes writing TypeScript a guessing game. |
@fruchtose at the risk of being obvious, us crashing is not a way of us telling you not to write a particular piece of code 😉 |
@RyanCavanaugh, I apologize if my response comes across as harsh. It's an issue that's started to crop up lately in my TS work. While it it's frustrating to have an issue to point to, it's a bit of a relief as well to identify a possible root cause. |
My team is also facing the same issue. Devs are getting annoyed, since we can not run incremental builds for TDD any more. Unfortunately it is closed source. But here is what i can tell so far.
When i search the project for type declarations, i can find about 134 matches. According to the comments above, those types wont be cached and may lead to out of memory. I tried to declare those types differently. Some simple types can not be rewritten. Those look like export type BrandColorName =
"" |
"dark" |
"primary" |
"secondary" |
"success" |
"warning" |
"danger" |
"info" Majority of our types have been changed from this import { AbstractControl } from "@angular/forms"
export class MyModel {
// ...
}
export type MyModelForm = { [K in keyof MyModel]: AbstractControl } to this import { AbstractControl } from "@angular/forms"
export class MyModel {
// ...
}
// next line is changed
export interface MyModelForm = { [K: string]: AbstractControl } unfortunately this did not help. I still can get into the out the of memory crash. I can not say if the changes helped at least a bit, since i have no idea how to measure the compilers workload. I would appreciate any guide or hint how i could do that. Even if the changes would have helped, i'd still prefer the type declaration like it was before the change since it helps us in 3 ways
|
@giniedp Probably your problem is deeper than OP's problem. And changing type alias to interface does not work probably proves it. It seems that you have a quite large project. My suggestion is:
Hope this helps. |
@HerringtonDarkholme Confirming that changing every instance of |
just to let you know. If i separate the typescript compilation from webpack then the bare |
@bcherny Here are some notes from investigating your repro. The way that compilation fails on your repro is as follows: When type checking Eventually, compilation gets stuck in a loop between None.flatMap and MonadNone.chain. After it checks that the parameters of each are assignable to the other, it has to examine the return types. The return types are There is a fix in master that improves relationship checking for generic types, but it doesn't apply to type aliases. However, even extending that fix to type aliases doesn't prevent the oomemory crash. I think that's because the type argument is not a simple type variable. It's |
Not sure if this is covered here or elsewhere already, but a similar error is thrown by this code (though it's a stack overflow, not heap): interface A<B = A> {
a: B
}
|
@bcherny No, that's an unrelated problem, I will open a new issue. |
Repro case: https://github.com/bcherny/tsoption/blob/7ae2d5d/index.ts (tree)
Repro steps:
npm install
./node_modules/.bin/tsc
Node version: 6.9.5
TypeScript version: 2.4.1
Error output:
The text was updated successfully, but these errors were encountered: