Skip to content

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

Closed
@AnyhowStep

Description

@AnyhowStep

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);

Activity

weswigham

weswigham commented on Dec 25, 2018

@weswigham
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.

added
QuestionAn issue which isn't directly actionable in code
APIRelates to the public API for TypeScript
on Dec 25, 2018
AnyhowStep

AnyhowStep commented on Dec 25, 2018

@AnyhowStep
ContributorAuthor

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

Merry Christmas!

Blasz

Blasz commented on Sep 2, 2019

@Blasz
Contributor

Relates to #17944

AnyhowStep

AnyhowStep commented on Sep 2, 2019

@AnyhowStep
ContributorAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIRelates to the public API for TypeScriptQuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Blasz@weswigham@AnyhowStep

        Issue actions

          [API Question] Union types in error output changes order of elements arbitrarily · Issue #29146 · microsoft/TypeScript