-
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
Convince Monaco/TSC a TS file is actually a function body? #1452
Comments
We had the same problem a while back (see #1069) and currently we just filter out this special diagnostic. But I would be happier if there were a compiler option (though I guess that would need to be implemented directly in the TypeScript compiler). |
@TedDriggs Could you tell how did you solve the problem with type checking? I'm developing a game editor and need to tell monaco the context of the edited code (the meaning of |
I opened a PR that allows to ignore diagnostics by code. The narrowing effect is unaffected by that. Tested with the following JS code: /**
* @typedef {object} Success
* @property {"success"} type
* @property {number} result
*/
/**
* @typedef {object} Failure
* @property {"failure"} type
* @property {string} message
*/
/**
* @type {Success | Failure}
*/
let foo;
if (foo.type === "success")
return foo.result;
return foo.message; |
And I wrote tons of hacks that actually wrap code into a function.
|
monaco-editor version: 0.16.2
Browser: Chrome/Firefox
OS: macOS
Steps or JS usage snippet reproducing the issue:
Our product is embedding Monaco to let users edit JS code that we then wrap in a function and run in V8. We've successfully gotten full type and syntax checking working, but we've run into a new issue: Early returns are being flagged as errors.
Because we know that the code will be wrapped inside a function, the
return
is actually safe. However, we'd strongly prefer not to show users that wrapper function, and based on #664 it looks like adding hidden and non-editable content "around" the displayed text is either unsupported or undocumented.Is there a way to do this? Ideally, we'd do it in a way that keeps the type narrowing effect of the
return
statements, but we could settle for an approach that silenced that particular diagnostic if that was the only option.The text was updated successfully, but these errors were encountered: