-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
window.MonacoEnvironment isn’t defined in types. #2580
Comments
Thanks for the issue & the PR! |
The type of The PR sets the type of the global const foo = MonacoEnvironment; However, a typical use case is to set the global declare global {
interface Window {
MonacoEnvironment: Environment;
}
}
window.MonacoEnvironment = {
getWorker(workerId, label) {
switch (label) {
case 'css':
return new CssWorker();
case 'editorWorkerService':
return new MonacoWorker();
case 'json':
return new JsonWorker();
case 'yaml':
return new YamlWorker();
default:
throw new Error(`Unknown label ${label}`);
}
},
}; |
Sounds reasonable. But I would like to hear @alexdima's opinion on this before merging the PR. |
Another approach I’d personally like even better, is to get rid of the global import { setMonacoEnvironment } from 'monaco-editor/esm/vs/editor/editor.api';
// Both imports should work
// import { setMonacoEnvironment } from 'monaco-editor';
setMonacoEnvironment({
getWorker(workerId, label) {
switch (label) {
case 'css':
return new CssWorker();
case 'editorWorkerService':
return new MonacoWorker();
case 'json':
return new JsonWorker();
case 'yaml':
return new YamlWorker();
default:
throw new Error(`Unknown label ${label}`);
}
},
}); |
I like #2605 even better than my solution in the last comment. |
The types that have been added in microsoft/vscode#128949 are incorrect. Due to how the types are processed, the global /cc @alexdima |
monaco-editor version: 0.26.1
Browser: N/A
OS: N/A
Playground code that reproduces the issue: N/A
The following TypeScript code:
Yields:
window.MonacoEnvironment
isn’t defined by the type definitions, only the globalMonacoEnvironment
is.The text was updated successfully, but these errors were encountered: