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

[Bug] typescriptDefaults.setExtraLibs not working as expected #4678

Open
1 of 2 tasks
Torsten85 opened this issue Sep 12, 2024 · 1 comment
Open
1 of 2 tasks

[Bug] typescriptDefaults.setExtraLibs not working as expected #4678

Torsten85 opened this issue Sep 12, 2024 · 1 comment

Comments

@Torsten85
Copy link

Torsten85 commented Sep 12, 2024

Reproducible in vscode.dev or in VS Code Desktop?

  • Not reproducible in vscode.dev or VS Code Desktop

Reproducible in the monaco editor playground?

Monaco Editor Playground Link

https://microsoft.github.io/monaco-editor/playground.html?source=v0.51.0#XQAAAAK4BQAAAAAAAABBqQkHQ5NjdQultUhUwcsQIjjaoVayL-wYsMeg24JItvniWevaGyL6ot7GNI6RFj5KIZKnPs8bDABIDSRRqux-oVQT185N0-S9kY8B6TtqQu6-29b1SJjdE3dN-UK1KVtCc43xLj9Jo3QOMz5EH-2xH_NeNavjeq3BMdfl-VDtZ2z4OjBhFRpkU34K6geDzpm9ooZGKEw-1c_GUgYGqEt40F0TiTqOUENu33HWjGIMJoOed9lxM0i_6O2wc5leZUMgfmL5n_viyd8lS-EAz_5V70Qe81d8GDmQ_o6mJXIowRoIlmoe7j9JhyAXd_fvpo5iEjWJ9qMsLL6oLgAiZiEGCydSMzyxrjO_ScgGz1yYlQH-8HiFrosCXcN2p8FUU9tkdYs36UYzHdzIQ0vzvthQaPZg8-qOOJe_RgJyYYYZgyyy2mdncrHPRwWGegmz0o6n2NxsfNI43i7C-Ac3Aqlm_-nQl31MQdrbVTQb9ILdDFiBnIDpQAOu61BDhk8pxnirzVEjBQV4xrOprdpoTaSAq8z_MLAfWXNYZx3NEZq9-ALnVEvh2YanLIN3E3tt89YyIhgPEmh4CjfSs6TPh9LWavKNHV2GKqgIxyxShS2b2tDBcvWRduYVoPob7qD-gAawYRSn9yEd_m9rT69Qz7E2BrKKNva2wbjdb6jbep8W-9fuCdb3EZdGaskKppTIBNZ6l-b9OmTXADGUjrMyocd5kPPKB2RNN1ftYNOD8Hc__-R0qcc

Monaco Editor Playground Code

monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
	allowNonTsExtensions: true,
  	moduleDetection: 3, // @see https://github.com/microsoft/monaco-editor/issues/2976#issuecomment-2334468503
})

const myEditor1 = monaco.editor.create(document.getElementById("container1"), {
	value: `// when this editor has focus, line 2 should be valid and line 3 should show an error
const a = api.thisShouldWorkInTheTopEditor()
const b = api.thisShouldWorkInTheBottomEditor()
`,
	language: "typescript",
});

myEditor1.onDidFocusEditorWidget(() => {
	 monaco.languages.typescript.typescriptDefaults.setExtraLibs([
		{
			content: `
				interface Api {
					thisShouldWorkInTheTopEditor(): string
				}

				declare const api: Api
			`,
			filePath: 'globals.d.ts'
		}
	])
})

const myEditor2 = monaco.editor.create(document.getElementById("container2"), {
	value: `// when this editor has focus, line 2 should show an error and line 3 should be valid
const a = api.thisShouldWorkInTheTopEditor()
const b = api.thisShouldWorkInTheBottomEditor()
`,
	language: "typescript",
});

myEditor2.onDidFocusEditorWidget(() => {
	 monaco.languages.typescript.typescriptDefaults.setExtraLibs([
		{
			content: `
				interface Api {
					thisShouldWorkInTheBottomEditor(): string
				}

				declare const api: Api
			`,
			filePath: 'globals.d.ts'
		}
	])
})

Reproduction Steps

  • You see two editors, both show typescript errors
  • Focus the upper editor, line 2 get valid, line 3 has an error (correct!)
  • Focus the lower editor, now both lines are correct (error!)

Actual (Problematic) Behavior

setExtraLibs seems to merge the extra libs instead of replacing the existing libs

Expected Behavior

setExtraLibs should correctly replace all the existing libs

Additional Context

the latest version where the behaviour of setExtraLibs is correct is 0.36.1 .
But I can't manage to isolate the modules in 0.36.1 without an export, so downgrading is no option for me

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

1 participant