Skip to content
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

Opening files in different order in IDE produces different errors #1953

Closed
JsonFreeman opened this issue Feb 6, 2015 · 5 comments
Closed
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@JsonFreeman
Copy link
Contributor

JsonFreeman commented Feb 6, 2015

0.ts:

///<reference path="1.ts"/>
///<reference path="2.ts"/>
var i: A | B;
var param: any;
i.foo(param); // May or may not produce an error

1.ts:

///<reference path="0.ts"/>
///<reference path="2.ts"/>
interface A {
    foo(): string;
}

2.ts:

///<reference path="0.ts"/>
///<reference path="1.ts"/>
interface B {
    foo(x?): string;
}

These three files form a clique because they all reference each other. If you start with none of these files open, and then open them, you may or may not get an error depending on the order that you open the files. Specifically, if you open file 0.ts or 1.ts first, you get an error. But if you open 2.ts first, you get no error.

This has to do with the nondeterministic order of types for union type collapsing.

This also means that the order the IDE calls getSemanticDiagnostics on the files is important, as it could lead to different outcomes. For compile-on-save, we call getSemanticDiagnostics on just the file we are saving. But in order to get a consistent outcome, we would have to call getSemanicDiagnostics on all the files in a canonical order, every time a file is saved. This means many files may have to be type checked before you can emit the file you've saved.

@JsonFreeman
Copy link
Contributor Author

This could be fixed by adding a stricter subtype rule for optional parameters versus absent parameters

@mhegazy mhegazy modified the milestones: TypeScript 2.0, TypeScript 1.6 Jul 1, 2015
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jul 27, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Jul 27, 2015

This should be fixed after the strict object literal changes

@mhegazy mhegazy closed this as completed Jul 27, 2015
@DanielRosenwasser
Copy link
Member

This should be fixed after the strict object literal changes

What exactly is the reason for that?

@danquirk
Copy link
Member

@DanielRosenwasser I believe because

This has to do with the nondeterministic order of types for union type collapsing.

is no longer relevant as subtype reduction for union types was removed as part of the strict object literal changes. We should double check that this actually no longer repros though.

@JsonFreeman
Copy link
Contributor Author

It isn't really because we eliminated subtype reduction in that change. We did in fact eliminate subtype reduction. But more importantly we eliminating the sorting of union constituents by type id. That was the source of the nondeterminism.

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants