fix(compiler): Generates function expressions as returning any (#9980)
Function expressions are used in an expression context so untyped function expressions should have any as the result type. Fixes: #9877
This commit is contained in:
@ -170,7 +170,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
|
||||
ctx.print(`(`);
|
||||
this._visitParams(ast.params, ctx);
|
||||
ctx.print(`):`);
|
||||
this.visitType(ast.type, ctx, 'void');
|
||||
this.visitType(ast.type, ctx);
|
||||
ctx.println(` => {`);
|
||||
ctx.incIndent();
|
||||
this.visitAllStatements(ast.statements, ctx);
|
||||
|
@ -143,11 +143,11 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should support function expressions', () => {
|
||||
expect(emitStmt(o.fn([], []).toStmt())).toEqual(['():void => {', '};'].join('\n'));
|
||||
expect(emitStmt(o.fn([], []).toStmt())).toEqual(['():any => {', '};'].join('\n'));
|
||||
expect(emitStmt(o.fn([], [new o.ReturnStatement(o.literal(1))], o.INT_TYPE).toStmt()))
|
||||
.toEqual(['():number => {', ' return 1;\n};'].join('\n'));
|
||||
expect(emitStmt(o.fn([new o.FnParam('param1', o.INT_TYPE)], []).toStmt())).toEqual([
|
||||
'(param1:number):void => {', '};'
|
||||
'(param1:number):any => {', '};'
|
||||
].join('\n'));
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user