Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fe2098c

Browse filesBrowse files
authored
Resolve bug inferring context type from generic functions in type parameters (#1589)
* Resolve bug inferring context type from generic functions in type parameters * remove previous fix * Fix false positive due to incorrect inference of generic function contraint
1 parent b40b43c commit fe2098c
Copy full SHA for fe2098c

2 files changed

+21Lines changed: 21 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/transformation/utils/function-context.ts‎

Copy file name to clipboardExpand all lines: src/transformation/utils/function-context.ts
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ function computeDeclarationContextType(context: TransformationContext, signature
140140
return ContextType.NonVoid;
141141
}
142142

143+
if (signatureDeclaration.parent && ts.isTypeParameterDeclaration(signatureDeclaration.parent)) {
144+
return ContextType.NonVoid;
145+
}
146+
143147
// When using --noImplicitSelf and the signature is defined in a file targeted by the program apply the @noSelf rule.
144148
const program = context.program;
145149
const options = program.getCompilerOptions() as CompilerOptions;
Collapse file

‎test/unit/functions/validation/validFunctionAssignments.spec.ts‎

Copy file name to clipboardExpand all lines: test/unit/functions/validation/validFunctionAssignments.spec.ts
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,20 @@ test("Does not fail on union type signatures (#896)", () => {
248248
)
249249
.expectToHaveNoDiagnostics();
250250
});
251+
252+
// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1568
253+
test("No false positives when using generic functions (#1568)", () => {
254+
util.testModule`
255+
/** @noSelf */
256+
declare namespace Test {
257+
export function testCallback<T extends (...args: any[]) => void>(
258+
callback: T,
259+
): void;
260+
}
261+
262+
Test.testCallback(() => {});
263+
264+
const f = () => {};
265+
Test.testCallback(f);
266+
`.expectToHaveNoDiagnostics();
267+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.