Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error TS2339: Property 'name' does not exist on type 'Function'

Tags:

typescript

I have the following function:

export function output(functions: Function[], inputs: unknown[]) {
    for (let func of functions) {
        console.log(`=== ${func.name} ===`);
        for (let input of inputs) {
            console.log(`"${input}"\t-> ${func(input)}`);
        }
        console.log();
    }
}

It works fine. However the tsc compiler complains on this line:

console.log(`=== ${func.name} ===`);

Saying:

Error TS2339: Property 'name' does not exist on type 'Function'.

What is causing the issue?

like image 291
Francesco Borzi Avatar asked Dec 03 '25 09:12

Francesco Borzi


1 Answers

I was able to reproduce this problem. It looks like the lib.d.ts file that defines the interface for Function doesn't have "name" as a property.

See Typescript Issue 6623, which has a workaround.

The name property on interface Function is defined in lib.es6.d.ts. If you compile with --target ES6 you should see it.

like image 63
DaveG Avatar answered Dec 05 '25 00:12

DaveG