microsoft / microsoft/TypeScript
Declare type to be an import depending on a string literal argument: typeof import(name);
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Hello,
It's seems to be difficult to do but there's now a lot of possibilities with the typescript compiler that I wouldn't have thought possible before, so I prefer to ask.
Is there a chance to have this kind of definition:
declare function require(name: string): typeof import(name) | undefined;
I mean declaring the return type as the type coming from the import of module "name". So we could have the type returned by require:
var module = require("my module");
I guess if it's feasible, it will also be possible to add more typing on this kind of javascript code
define("myModule, ["deps1", "deps2", "deps3"], (deps1, deps2, deps3) => {
// deps1, deps2, deps3 have the right type !!
});
like this
define("myModule, ["deps1", "deps2", "deps3"], (deps1: typeof import("deps1"), deps2: typeof import("deps2"), deps3: : typeof import("deps3")) => {
// deps1, deps2, deps3 have the right type !!
});
Thanks for your help,
--
Laurent
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by investigating whether the TypeScript compiler can make typeof import(name) depend on a string literal and use that result for require and define calls. Review the issue's examples and determine the language and type-checking changes needed; done would mean the requested module types are inferred from literal arguments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100