You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Observe the error listed below in "Actual behavior".
Switch to a branch where order of type declarations is slightly modified (type Footer is moved higher in the file): git checkout modified-type-order; or use the following diff:
Incorrectly reported error in the initial example:
src/query.transformer.ts:23:7 - error TS2322: Type 'Footer[] | undefined' is not assignable to type 'FooterTransformer | null | undefined'.
Property 'field' is missing in type 'Footer[]' but required in type 'FooterTransformer'.
23 const y: FooterTransformer | null | undefined = x;
~
src/query.transformer.ts:9:3
9 field: unknown;
~~~~~
'field' is declared here.
After changing the order of type declarations, the code compiles successfully.
In IDEs (e.g. VS Code) you wouldn't see any errors (the types are inferred as expected).
π Expected behavior
The compiler's behavior is consistent regardless of the order of type declarations. (No error is expected in either case because the types in question are compatible.)
Additional information about the issue
This seems to be a bug somewhere deep down in the TS compiler. It may have something to do with types circularly referencing each other.
There are a few seeming unrelated ways to make the error disappear, e.g. by trying any of the following:
Removing Entry & from types;
Removing | {} union inside the FooterLinksGroup type;
Putting all code into a single file.
All this additionally confirms that this is a compiler bug and not a feature.
This is a bug I encountered in production and tried to reduce the example as much as possible. The need for a build with API instead of the CLI arises from the fact that my original code uses Nest CLI which internally uses the TS compiler API.
The text was updated successfully, but these errors were encountered:
π Search Terms
N/A β this is a very specific case, and I'm not sure which part of the code sample causes the bug.
π Version & Regression Information
Tested on all versions starting from
5.0.1
. The example repo uses5.3.0-dev.20230905
.β― Playground Link
https://github.com/SimpleCreations/typescipt-compiler-inconsistent-behavior-poc
π» Code
Steps to reproduce:
yarn install
node ./build.mjs
Observe the error listed below in "Actual behavior".
type
declarations is slightly modified (type Footer
is moved higher in the file):git checkout modified-type-order
; or use the following diff:node ./build.mjs
Observe no error.
π Actual behavior
type
declarations, the code compiles successfully.π Expected behavior
The compiler's behavior is consistent regardless of the order of type declarations. (No error is expected in either case because the types in question are compatible.)
Additional information about the issue
This seems to be a bug somewhere deep down in the TS compiler. It may have something to do with types circularly referencing each other.
There are a few seeming unrelated ways to make the error disappear, e.g. by trying any of the following:
Entry &
from types;| {}
union inside theFooterLinksGroup
type;All this additionally confirms that this is a compiler bug and not a feature.
This is a bug I encountered in production and tried to reduce the example as much as possible. The need for a build with API instead of the CLI arises from the fact that my original code uses Nest CLI which internally uses the TS compiler API.
The text was updated successfully, but these errors were encountered: