sample.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Add additonal d.ts files to the JavaScript language service and change.
  2. // Also change the default compilation options.
  3. // The sample below shows how a class Facts is declared and introduced
  4. // to the system and how the compiler is told to use ES6 (target=2).
  5. // validation settings
  6. monaco.languages.typescript.javascriptDefaults.setDiagnosticsOptions({
  7. noSemanticValidation: true,
  8. noSyntaxValidation: false
  9. });
  10. // compiler options
  11. monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
  12. target: monaco.languages.typescript.ScriptTarget.ES6,
  13. allowNonTsExtensions: true
  14. });
  15. // extra libraries
  16. monaco.languages.typescript.javascriptDefaults.addExtraLib([
  17. 'declare class Facts {',
  18. ' /**',
  19. ' * Returns the next fact',
  20. ' */',
  21. ' static next():string',
  22. '}',
  23. ].join('\n'), 'filename/facts.d.ts');
  24. var jsCode = [
  25. '"use strict";',
  26. '',
  27. "class Chuck {",
  28. " greet() {",
  29. " return Facts.next();",
  30. " }",
  31. "}"
  32. ].join('\n');
  33. monaco.editor.create(document.getElementById("container"), {
  34. value: jsCode,
  35. language: "javascript"
  36. });