8
votes

Hi I'm new in Typescript, I have an object-type variable in which might be different values from different types or nested object. now my question is that how can I define a model for this object to don't face the example error when call different keys?

For example:

export class Controller {
protected static response(res: Response, statusCode: number = 200, data: any, user: string = '', dev: string = '', code: number = 200, result: string = 'success'){
    res.status(statusCode).send({
        data: data,
        message: {
            user: '',
            dev: ''
        },
        code: 403,
        result: 'Error'
    })
}


 ERROR: res.status ---> This expression is not callable. Type 'Number' has no call signatures
3

3 Answers

15
votes

I was getting this error as well, and realized I'd just forgotten to import Response. Adding an import line solved the problem for me.

import express, {Request, Response} from 'express';
1
votes

res.status is a number according to that error message. It doesn't look like that Controller is being called with the correct arguments. console.log(res) in there before calling res.status and check your call site code.

1
votes

In case it helps anyone else, I have also seen the same error in cases like this:

const shift = progressWidth * percentage
(this.$refs.expected as Vue).$el.style.left = "100px"

Where percentage is a number. The error occurs because without semicolons the second line is being interpreted as part of the line, like this:

const shift = progressWidth * percentage(this.$refs.expected as Vue).$el.style.left = "100px"

This can be fixed by adding a leading semi-colon:

const shift = progressWidth * percentage
;(this.$refs.expected as Vue).$el.style.left = "100px"

Or even better, rearrange so it isn't needed at all:

const expected = (this.$refs.expected as Vue).$el
const shift = progressWidth * percentage
expected.$el.style.left = "100px"