Skip to content

Commit 721d368

Browse files
authored
Fixed bug where 'JS$Function' was being generated instead of just 'Function' for the TypeScript Function type
1 parent f4e05b9 commit 721d368

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/facade_converter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ export class FacadeConverter extends base.TranspilerBase {
411411
// https://www.typescriptlang.org/docs/handbook/utility-types.html
412412
const type = node.typeName.getText();
413413
switch (type) {
414+
case 'Function':
415+
// We check this case to prevent generating JS$Function for the name; the keyword
416+
// Function may be used as a type but not in other cases
417+
name = 'Function';
418+
break;
414419
case 'Partial':
415420
// Partial<X> is currently the same as X since all types are nullable in Dart
416421
name = this.generateDartTypeName(node.typeArguments[0]);

test/type_test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ external set x(List<String> v);`);
101101
external String Function(String) get x;
102102
@JS()
103103
external set x(String Function(String) v);`);
104+
105+
expectTranslate('declare var a: Function').to.equal(`@JS()
106+
external Function get a;
107+
@JS()
108+
external set a(Function v);`);
104109
});
105110

106111
describe('TypeScript utility types and other mapped types', () => {

0 commit comments

Comments
 (0)