Skip to content

Instantly share code, notes, and snippets.

@keroserene
Created March 26, 2014 20:51
Show Gist options
  • Save keroserene/9793166 to your computer and use it in GitHub Desktop.
Save keroserene/9793166 to your computer and use it in GitHub Desktop.
Typescript void generic problem
interface Foo<T> {
bar<T2>(callback:(t:T)=>T2) : T2;
}
var foo :Foo<string>;
// Works as expected.
foo.bar<number>((s:string) => {
return 12345;
});
// Succeeds silently when it should actually fail...
foo.bar<void>((s:string) => {
return 5; // Not a void!!!
});
// Fails as expected.
foo.bar<number>((s:string) => {
});
// Fails as expected.
foo.bar((n:number) => {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment