question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Explore enabling type acquisition for web TS Server

See original GitHub issue

Follow up on #39707

Overview

We now have TSServer running in web environments, but it is currently limited to single file intellisense. It would be nice if we could also offer some IntelliSense for third party packages that are imported in the current file.

If a user is trying out react for example, we should be able to offer IntelliSense for React and ReactDOM:

//@ts-check

import * as React from 'react';
import * as ReactDOM from 'react-dom';

class HelloMessage extends React.Component {
    render() {
        return (
            <div>
                Hello {this.props.name}
            </div>
        );
    }
}

ReactDOM.render(
    <HelloMessage name="Taylor" />,
    document.getElementById('hello-example')
);

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
ortacommented, Aug 25, 2021

I recently re-wrote the ATA for the Playground ( https://github.com/microsoft/TypeScript-Website/pull/1997 ) in what I think is a pretty good conceptual pattern:

  • TypeScript can probably already give you a list of dependencies it knows about from the package.json, and the source files it has read (in the playground I don’t have this, so I use ts.preprocessFile to extract that)
  • You make an API call which gets a list of all the files in each module tarball (I used jsDelivr’s) from which you can figure out the list of .d.ts files you need to download, or that you need to check DT.
  • If you need to check for @types/module and grab the .d.ts files for that module
  • Loop through all the downloaded .d.ts files and recurse grabbing their modules etc

It’s not exactly like that in practice (you need the version number before you can make that API call to jsdelivr) - but that’s good enough and you can read the implementation linked above for more details. The implementation of the TypeScript Playground ATA is built for third parties, so you could be a consumer of @typescript/ata when that PR lands.

An ideal state for VS Code which would keep this entirely first-party, is that the npm registry adds two APIs like:

  • https://registry.npmjs.org/npm/:version_or_tag/contents which returns some sort of file list
  • https://registry.npmjs.org/npm/:version_or_tag/file/package.json which returns a CDN’d file from the tarball (in this case the package.json)

Or vscode creates an API which proxies these APIs to jsdelivr (they’re real nice folks, I can make an intro if needed) which allows for other implementations behind the scenes in time.

2reactions
MartinKolarikcommented, Sep 2, 2021

Or vscode creates an API which proxies these APIs to jsdelivr (they’re real nice folks, I can make an intro if needed)

We are already watching - ping me any time if needed 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Investigate entities on devices using live response
Live response is designed to enhance investigations by enabling your security operations team to collect forensic data, run scripts, ...
Read more >
TSConfig Reference - Docs on every TSConfig option
Enabling the option allows importing JSON, and validating the types in that JSON file. ts. // @filename: settings.json. {. "repo" ...
Read more >
Remote Development Tips and Tricks - Visual Studio Code
Visual Studio Code Remote Development troubleshooting tips and tricks for SSH, Containers, and the Windows Subsystem for Linux (WSL)
Read more >
./orta@mastodon.social --degrowth -- on Twitter: "- Spaghetti ...
It's now much simpler and leans on the TS compiler much more to do the complex stuff. ... Explore enabling type acquisition for...
Read more >
Usage - code-server v4.8.0 docs - Coder
This option requires that the remote machine be exposed to the internet. Make sure that your instance allows HTTP/HTTPS traffic. You'll need a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found