Skip to content

[API Question] Union types in error output changes order of elements arbitrarily #29146

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

Closed
AnyhowStep opened this issue Dec 25, 2018 · 4 comments
Labels
API Relates to the public API for TypeScript Question An issue which isn't directly actionable in code

Comments

@AnyhowStep
Copy link
Contributor

image

I'm writing a library and have a crude compile-time test system set up. I run the test and it compiles a bunch of snippets and compares the actual compiled output (declarations and errors) to the expected compiled output.

However, I've noticed that, every once in a while, when adding new features, the compiled output changes like in the above screenshot. The output isn't wrong per se. It's correct but adding a new file shouldn't change the compiled output (in my opinion).

It's just shuffling the elements of the union types in the error messages.

When the output does change, I just accept the change and subsequent compiles match the new output. So, I know the compile output is deterministic. It just seems like adding a new file and not modifying every other file has the possibility of changing the compile output... Of code that doesn't use the new file.


  1. Code A uses File A
  2. I add File B, I do not modify Code A or File A
  3. I compile
  4. Code A's output changes

I guess my question is "Why is it doing this?"


Below is how I'm compiling the snippets,

const rootNames = getAllTsFiles(inputRoot);
const program = ts.createProgram({
    rootNames,
    options : compilerOptions,
});
const emitResult = program.emit(
    /*snip*/
);
const allDiagnostics = ts
    .getPreEmitDiagnostics(program)
    .concat(emitResult.diagnostics);
@weswigham
Copy link
Member

The order or types in members is determined by those types IDs. Type IDs are assigned on a first-checked basis. So adding a file can cause they type to be checked sooner and thus it's order in a union change.

@weswigham weswigham added Question An issue which isn't directly actionable in code API Relates to the public API for TypeScript labels Dec 25, 2018
@AnyhowStep
Copy link
Contributor Author

Ah. That makes sense to me. Thanks for the response!

Merry Christmas!

@Blasz
Copy link
Contributor

Blasz commented Sep 2, 2019

Relates to #17944

@AnyhowStep
Copy link
Contributor Author

#32224

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Relates to the public API for TypeScript Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants