Last active
October 15, 2018 14:21
-
-
Save minajevs/e93f1ad12160ebfadd77185d68dac6dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo<T>(arg: T) { | |
if (arg === undefined) | |
doThis() | |
else | |
doThat(arg) | |
} | |
// number | |
foo<number>(42) // OK | |
foo<number>() // ERROR: 1 argument expected | |
foo<number>("bar") // ERROR: 'bar' is not assignable 'number'. | |
// undefined | |
foo<undefined>() // ERROR: 1 argument expected, BUT we would like it to be possible! | |
foo<undefined>(41) // ERROR: '42' is not assignable to 'undefined' | |
foo<undefined>(undefined) // OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment