Skip to content
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

Changes in JSON files cause stale TS errors in ts/tsx files #60241

Open
DonnyVerduijn opened this issue Oct 15, 2024 · 1 comment
Open

Changes in JSON files cause stale TS errors in ts/tsx files #60241

DonnyVerduijn opened this issue Oct 15, 2024 · 1 comment

Comments

@DonnyVerduijn
Copy link

Type: Bug

  1. Configure a TS project to allow JSON imports
  2. Import a JSON file into a TS/TSX file.
  3. Use the type information from the JSON file to infer different types.
  4. Change the contents of the JSON file.
  5. Navigate back to the TS file.
  6. Observe that any TS errors become stale/new errors are not visible. Only restarting the server helps.

VS Code version: Code 1.94.2 (Universal) (384ff7382de624fb94dbaf6da11977bba1ecd427, 2024-10-09T16:08:44.566Z)
OS version: Darwin arm64 24.0.0
Modes:
Remote OS version: Linux arm64 6.8.0-45-generic

System Info
Item Value
CPUs Apple M1 (8 x 2400)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) 3, 3, 3
Memory (System) 16.00GB (0.04GB free)
Process Argv --crash-reporter-id 9e5b74d3-969a-40a2-b2e5-561acacb1e0a
Screen Reader no
VM 0%
Item Value
Remote Dev Container: Node.js & GitHub Actions @ 172.16.44.136
OS Linux arm64 6.8.0-45-generic
CPUs unknown (4 x 0)
Memory (System) 7.74GB (1.45GB free)
VM 0%
Extensions (27)
Extension Author (truncated) Version
better-comments aar 3.0.2
remote-containers ms- 0.389.0
remote-ssh ms- 0.115.0
remote-ssh-edit ms- 0.87.0
vscode-remote-extensionpack ms- 0.25.0
remote-explorer ms- 0.4.3
remote-server ms- 1.5.2
vscode-speech ms- 0.10.0
vscode-eslint dba 3.0.10
gitlens eam 15.6.1
effect-vscode eff 0.1.6
auto-run-command gab 1.6.0
copilot Git 1.238.0
copilot-chat Git 0.21.2
vscode-github-actions git 0.27.0
vscode-pull-request-github Git 0.98.0
todo-tree Gru 0.0.226
vscode-docker ms- 1.29.3
vscode-kubernetes-tools ms- 1.3.18
resourcemonitor mut 1.0.7
vscode-yaml red 1.15.0
preview-vscode sea 2.3.7
vscode-styled-components sty 1.7.8
vscode-stylelint sty 1.4.0
explorer vit 1.6.0
vscode-css-variables vun 2.7.1
pretty-ts-errors Yoa 0.6.0
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
pythonnoceb:30805159
asynctok:30898717
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
accentitlementst:30995554
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
f3je6385:31013174
a69g1124:31058053
dvdeprecation:31068756
dwnewjupyter:31046869
impr_priority:31102340
nativerepl2:31139839
refactort:31108082
pythonrstrctxt:31112756
wkspc-onlycs-t:31132770
wkspc-ranged-t:31151552
cf971741:31144450
autoexpandse:31146404
iacca2:31156134
notype1:31157159
5fd0e150:31155592
iconenabled:31158251

@DonnyVerduijn
Copy link
Author

DonnyVerduijn commented Oct 15, 2024

The following code can be used to reproduce the error. Note that requiredKey should be in both the json files to avoid producing any type mismatch.

import type { Booleans, Fn, Pipe, Tuples } from 'hotscript';
import type { IsNever } from 'type-fest';
import type { default as DataTypeEN } from './../public/locales/en/translation.json';
import type { default as DataTypeNL } from './../public/locales/nl/translation.json';

type Locales = [typeof DataTypeEN, typeof DataTypeNL];

interface ContainsFn<T> extends Fn {
  return: IsNever<Exclude<keyof T, keyof this['arg0']>>;
}

export type TranslationAvailable<T> = Pipe<
  Locales,
  [
    Tuples.Map<ContainsFn<T>>,
    Tuples.Some<Booleans.Extends<false>>,
    Booleans.Not,
  ]
>;

let foo: TranslationAvailable<{ requiredKey: string }> = true;

In the image below, you can see that the popup, shows the updated type, but the error is not visible in the editor by a squiggle, except for the unrelated warnings which were already present.

After changing the JSON file (changing requiredKey to requiredK for example), we can observe that the error does also not propagate when the change is matched in the TS file by updating that file. So it seems that the JSON files themselves cause a stale cache that prevents any TS errors in opened files to become visible automatically.

Image

After restarting the TS server the error is shown immediately as seen below:

Image

@mjbvz mjbvz transferred this issue from microsoft/vscode Oct 16, 2024
@mjbvz mjbvz removed their assignment Oct 16, 2024
@DonnyVerduijn DonnyVerduijn changed the title changes in JSON files cause stale TS errors in ts/tsx files Changes in JSON files cause stale TS errors in ts/tsx files Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants