diff --git a/src/suggestion/getNodeSuggestions.ts b/src/suggestion/getNodeSuggestions.ts index 40cffd0..dfa5a64 100644 --- a/src/suggestion/getNodeSuggestions.ts +++ b/src/suggestion/getNodeSuggestions.ts @@ -35,7 +35,6 @@ export const getNodeSuggestions = ( ${functions?.map((_, i) => `const check${i}: TargetType = {} as F${i};`).join("\n")} `; - const fileName = "index.ts"; const host = createCompilerHost(fileName, sourceCode); const sourceFile = host.getSourceFile(fileName)!; diff --git a/src/utils.ts b/src/utils.ts index 143cfdf..950bfe7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -46,6 +46,12 @@ export const MINIMAL_LIB = ` interface NewableFunction extends Function {} interface IArguments { } interface RegExp { } + + declare namespace Utils { + type ReturnType any> = T extends (...args: any) => infer R ? R : any; + } + + import ReturnType = Utils.ReturnType; `; /** diff --git a/test/nodeSuggestion.test.ts b/test/nodeSuggestion.test.ts index 6058b0e..5254654 100644 --- a/test/nodeSuggestion.test.ts +++ b/test/nodeSuggestion.test.ts @@ -44,6 +44,10 @@ describe("getNodeSuggestions", () => { 'std::control::value' ])) + expect(map).toEqual(expect.not.arrayContaining([ + "std::number::add" + ])) + }); it("should suggest functions with compatible return types and prioritize exact matches for boolean", () => {