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

Autocomplete Filepath Strings. #42054

Open
Griffork opened this issue Dec 19, 2020 · 4 comments
Open

Autocomplete Filepath Strings. #42054

Griffork opened this issue Dec 19, 2020 · 4 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@Griffork
Copy link

Search Terms

Autocomplete, fs, require, strings.

Suggestion

I would like to be able to mark a string as a relative path, and get autocomplete for it if it's initialised with a constant.

Examples

var path: tsRelativePath;
path = "./fi 
//pressing ctrl-space should autocomplete to ./file or ./file.txt.
fs.readFile("./fi 
//pressing ctrl-space should autocomplete to ./file or ./file.txt.

Obviously some name for the type that doesn't conflict with common type names will have to be chosen.

Use Cases

It would be nice to have autocomplete for fs.read etc.

I'm making a modified require.js library which allows me to use a custom import function on the client to load resources (html templates, css, 3D models, animations, shaders, etc.) relative to the current script file. I'd like to be able to get auto-complete on the paths and compiler errors if the resource doesn't exist (e.g. i forgot to build my scss files).

I would also like these paths to update when you move or rename a resource the same way paths update when you move or rename a script file.

I'm aware this functionality can be enabled in VSCode with plugins but I'm stuck using Visual Studio and would like it to be supported natively.

Checklist

My suggestion meets these guidelines:

  • [ y] This wouldn't be a breaking change in existing TypeScript/JavaScript code (as long as the type name is chosen well)
  • [ y] This wouldn't change the runtime behavior of existing JavaScript code
  • [ y] This could be implemented without emitting different JS based on the types of the expressions
  • [ y] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • [ y] This feature would agree with the rest of TypeScript's Design Goals.
@RyanCavanaugh RyanCavanaugh added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Dec 23, 2020
@mdbetancourt
Copy link

@RyanCavanaugh i want to see this too maybe as

function loadFile(filePath: FilePath) {}
// or allow this so there is not posibility with name collision with existing types
function loadFile(filePath: Parameters<typeof import>[0]) {}

loadFile('./|')
          // ^ ctrl + space return files autocomplete

same behavior as import

const mod = await import('./|')
                        // ^ ctrl + space return files autocomplete

@oliveryasuna
Copy link

This would be great for IDE auto-completion.

@xiBread
Copy link

xiBread commented Sep 3, 2023

There's a VSCode extension that does this. I don't see the point in having TS supporting this natively.

@oliveryasuna
Copy link

oliveryasuna commented Sep 6, 2023

There's a VSCode extension that does this. I don't see the point in having TS supporting this natively.

Not everyone is unfortunate enough to use VSCode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants