-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
Bug Report
🔎 Search Terms
- Declaration emit widens literal types in readonly properties.
🕗 Version & Regression Information
- This is a crash no
- This is the behavior in every version I tried : 4.7.3 and nightly build (4.8.0-dev.20220606)
- I reviewed the whole FAQ
⏯ Playground Link
Playground link with relevant code
💻 Code
const instance = {
program: ts.createSemanticDiagnosticsBuilderProgram,
host: options?.watch
? ts.createSolutionBuilderWithWatchHost
: ts.createSolutionBuilderHost,
builder: options?.watch
? ts.createSolutionBuilderWithWatch
: ts.createSolutionBuilder,
};
const host = instance.host(
ts.sys,
instance.program,
reportDiagnostic,
undefined,
undefined
);
const builder = instance.builder(host, options.references, {
verbose: false,
incremental: true,
force: false,
traceResolution: false,
});
builder.build();
🙁 Actual behavior
I was testing a module just now and I noticed that the typescrit was emitting an error that it shouldn't .. I went deeper and saw that the constants were being emitted but only with the type instead of the declared read value.
using tsc -b works as you can see in example 02, but with SolutionBuilder it is setting it to "string" instead of "redBright".
So I don't think it's some option not defined in my tsconfig, because with tsc it outputs as expected, but my implementation with solution builder doesn't.. I also don't see any parameters, or something like that in the solution settings "createSolutionBuilderHost" or "createSolutionBuilder" that relates to that.
Looking deeper I decided to compare the tsbuildinfo files, and I noticed this change!
I don't know how TS works under the hood, but I can deduce that this loading order here is causing the problem.
The first example builds using TSC from the command line! it works fine, the second one is using SolutionBuilder and it doesn't issue correctly.
What I can imagine is that in the first case "constants.ts" has already been loaded and is available for "plugin.ts" and with that it can output my reading values.
In the second case "plugin.ts" is being loaded before "constant.ts", so my read values are not available yet, and ts is defaulting to "string".
I tested it twice to see if these values would change in both builds, but they don't..
So that's my logic for that.
I also just encountered this similar issue #15881 but no solution.
Looking at the "build" method we don't have asynchronous code implicit there, so I can assume it's all synchronous, the order of references is also correct.. so I'll try to use other methods like "buildReferences" to see if I get something.
🙂 Expected behavior
Correctly issue read-only declarations using SolutionBuilder api.