Skip to content

Instantly share code, notes, and snippets.

@jbmilgrom
Created September 18, 2017 19:51
Show Gist options
  • Save jbmilgrom/d3f92554484f61b9d207660a92611444 to your computer and use it in GitHub Desktop.
Save jbmilgrom/d3f92554484f61b9d207660a92611444 to your computer and use it in GitHub Desktop.
Typescript: example of lesser number of parameters as a narrow type.
interface CallbackWithNameParameter {
cb: (name: string) => void
}
type CallbackWithNoParameter = () => void;
const aCallbackWithNoParameter: CallbackWithNoParameter = () => {};
const aCallback: CallbackWithNameParameter = { // okay
cb: aCallbackWithNoParameter
};
aCallback.cb(); // error
const aSecondCallback: CallbackWithNameParameter = { // error
cb: (num: number) => {}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment