October 25, 2024
Chicago 12, Melborne City, USA
javascript

How Monaco Editor completion items provider can be triggered when accessing a string literal property?


In this MonacoEdtior using code, I’ve created a javascript editor instance, and add a piece of typescript code as an extra lib to monaco:

var libSource = `
type State = {
    'address-audited_val': string;
    address: string;
};
const s: State = {
    'address-audited_val': '...',
    address: '...'
};
`
monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, "ts:filename/test.ts");
monaco.editor.createModel(libSource, "typescript", monaco.Uri.parse("ts:filename/test.ts"));
monaco.editor.create(document.getElementById("container"), {
    value: '',
    language: "javascript",
});

Run the code in playground

Unexpected/Current Behavior

When I input s. in monca editor, I can only get a completion item for address, not including one for address-audited_val. screenshot

Expected Behavior

When I input s. in monca editor, I can get the completion items for address and address-audited_val, just like the performance of vscode in this regard.

Question

As we know, the address-audited_val is the string literal property of State. My question is there any way to configure monca so that I can get the completion items for these string literal properties?



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video