M
M
mr_blond972017-11-24 16:05:25
JavaScript
mr_blond97, 2017-11-24 16:05:25

How to type js function with parameter in TypeScript?

Given:

function myFunction() {
            //...
        }
myFunction.m = null;

ts compiler message:
Property 'm' does not exist on type '() => void'.

How to type js function with parameter in TypeScript?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Kitmanov, 2017-11-24
@k12th

Something like this:

interface MyFunction {
    (): void;
    m: any;
}

Also see https://www.typescriptlang.org/docs/handbook/decla...

A
Andrey Perov, 2017-11-24
@SnaIP

This?

function add(x: number, y: number): number {
    return x + y;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question