0

I have a callback currently defined like so:

onShow: Function;

And is called like so:

if (this.onShow) {
    this.onShow({ $currentPosition: this.currentLatLngPosition });
}

The main issue with this is that its not typesafe. How can I change the signature of onShow to have better type safety?

I found out I could define it a little better like so

onShow: () => void;

But I could not figure out how to get the correct function arguments in there. This doesnt work:

onShow: ({ $currentPosition: google.maps.LatLng }) => void;

Note the weird json parameter syntax is an Angular component callback requirement.

1

1 Answer 1

3
interface Config {
    $currentPosition: string; // Or whatever the type of the property is.
}

type myFunc = (config: Config) => void;

You do not have to create an interface:

type myFunc = (config: { $currentPosition:string }) => void;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.