ss1
ss1

Reputation: 1191

What's the type of this function?

I would like to pass a function as argument, but I'm not able to figure out the type declaration, because it uses a syntax I'm not familiar with. I could use any, but I rather would like to avoid that.

The function in question is mapStateToProps. The goal is to pass the function itself as an argument in a type-safe way.

class Props {
    counterModel:CounterModel = null;
}
function mapStateToProps({counterModel}:Props) {
    return {
        counterModel
    };
}

The short form of the function is (if that helps in any way):

const mapStateToProps3 = ({counterModel}:Props) => ({counterModel});

Thanks!

Upvotes: 0

Views: 32

Answers (1)

Ryan Cavanaugh
Ryan Cavanaugh

Reputation: 221044

The type of mapStateToProps is (arg: Props) => { counterModel: CounterModel }.

If you want to use its type elsewhere, you can also just use the shortcut typeof mapStateToProps instead of rewriting it yourself manually.

Upvotes: 1

Related Questions