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

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

    Issue actions