Skip to content

Commit 176a936

Browse files
committed
feat: ignore return types for arrow functions.
Dart does not support closures with return types.
1 parent 76541aa commit 176a936

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/declaration.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,16 @@ class DeclarationTranspiler extends base.TranspilerStep {
223223
}
224224

225225
private visitFunctionLike(fn: ts.FunctionLikeDeclaration, accessor?: string) {
226-
if (fn.type) this.visit(fn.type);
226+
if (fn.type) {
227+
if (fn.kind === ts.SyntaxKind.ArrowFunction) {
228+
// Type is silently dropped for arrow functions, not supported in Dart.
229+
this.emit('/*');
230+
this.visit(fn.type);
231+
this.emit('*/');
232+
} else {
233+
this.visit(fn.type);
234+
}
235+
}
227236
if (accessor) this.emit(accessor);
228237
if (fn.name) this.visit(fn.name);
229238
// Dart does not even allow the parens of an empty param list on getter

test/function_test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ describe('functions', () => {
3838
() => { expectTranslate('var a = function() {}').to.equal(' var a = ( ) { } ;'); });
3939
it('translates fat arrow operator', () => {
4040
expectTranslate('var a = () => {}').to.equal(' var a = ( ) { } ;');
41+
expectTranslate('var a = (): string => {}').to.equal(' var a = /* String */ ( ) { } ;');
4142
expectTranslate('var a = (p) => isBlank(p)').to.equal(' var a = ( p ) => isBlank ( p ) ;');
4243
expectTranslate('var a = (p = null) => isBlank(p)')
4344
.to.equal(' var a = ( [ p = null ] ) => isBlank ( p ) ;');

0 commit comments

Comments
 (0)