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

Setting custom typescript libraries breaks the standard lib #669

Closed
TyOverby opened this issue Dec 16, 2017 · 10 comments
Closed

Setting custom typescript libraries breaks the standard lib #669

TyOverby opened this issue Dec 16, 2017 · 10 comments

Comments

@TyOverby
Copy link

monaco-editor version: 0.10.1 (and whatever version is on the monaco playground.
Browser: Firefox | Safari
OS: OSX
Steps or JS usage snippet reproducing the issue:

monaco.editor.create(document.getElementById("container"), {
	value: "var x = [1,2,3];\n",
	language: "typescript"
});

monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
    target: monaco.languages.typescript.ScriptTarget.ES5,
    lib: ["DOM", "ES5", "ScriptHost"] // these are the default libraries for the ES5 target
});
  • In the demo editor, type x. and notice that Array autocomplete does not show up.
  • Retype the first line to var x: number[] = [1,2,3].
  • Retype x. and notice that Array autocomplete does not show up.

It looks like the only way to get working standard library features like Array is to not use custom lib options.

@TyOverby
Copy link
Author

Workaround: use monaco.languages.typescript.typescriptDefaults.addExtraLib(<>, "lib.d.ts"); with the entire source of lib.d.ts

@TedDriggs
Copy link

Thanks for the workaround! I ran into the same issue back in September: #579

@dennis-yemelyanov
Copy link

Are there any plans to address this issue in the near future?

@dennis-yemelyanov
Copy link

@TyOverby , the workaround to use addExtraLib(<>, "lib.d.ts") doesn't seem to work for me and results in a syntax error because of "<>" (the first parameter). Is there a way to avoid this error?

@TyOverby
Copy link
Author

@dennis-yemelyanov: you aren't supposed to literally put <>, you should put

| the entire source of lib.d.ts

@dennis-yemelyanov
Copy link

Ah I see. Was trying to figure out a way do avoid downloading the source myself, but looks like that's the only option for now.

@attaboy
Copy link

attaboy commented Oct 1, 2018

This bug cost me several hours of confusion today as I tried to understand why neither Array<T> nor T[] worked but also didn't cause any obvious errors.

I'm trying to build a Typescript editor for editing Node.js modules, so I don't want the DOM or other browser-specific stuff.

@strutcode
Copy link

strutcode commented Oct 22, 2019

For anyone else still having this issue in 2019, here's a work around I came up with for Webpack:

// This require context needs typescript as a dev dependency
// Note this will add all of those files to your build even if you don't use them
const ctx = require.context('typescript/lib', true, /\.d\.ts$/)
// Reduce all the .d.ts files to a filename => content object
const allLibs = ctx.keys().reduce(
  (acc, k) => {
    acc[k] = ctx(k).default
    return acc
  },
  {}
)

monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
  target: monaco.languages.typescript.ScriptTarget.ES5,
  allowNonTsExtensions: true,
  noLib: true,
})

// Add every lib from the typescript source
Object.entries(allLibs).forEach(([filename, content]) => {
  // Potentially exclude some libs here

  monaco.languages.typescript.typescriptDefaults.addExtraLib(content, filename)
})

@IamFonky
Copy link

This bug cost me several hours of confusion today as I tried to understand why neither Array<T> nor T[] worked but also didn't cause any obvious errors.

I'm trying to build a Typescript editor for editing Node.js modules, so I don't want the DOM or other browser-specific stuff.

I'm currently doing the same kind of project. Be aware that using noLib option will kill the typescript inference capabilities.

I just opened an issue for that #1673

@alexdima
Copy link
Member

alexdima commented Dec 12, 2019

Let's track in #579

@alexdima alexdima added *question Issue represents a question, should be posted to StackOverflow (VS Code) and removed *question Issue represents a question, should be posted to StackOverflow (VS Code) labels Dec 12, 2019
@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants