Skip to content

Instantly share code, notes, and snippets.

@geon
Last active November 20, 2017 14:50
Show Gist options
  • Save geon/2e6b5302d06c3ecc5a1a392c83a74b60 to your computer and use it in GitHub Desktop.
Save geon/2e6b5302d06c3ecc5a1a392c83a74b60 to your computer and use it in GitHub Desktop.
console.log(myFunction());
const myConstant = "";
function myFunction(myArgument: string = myConstant): string {
return myArgument;
}
@geon
Copy link
Author

geon commented Nov 20, 2017

You would expect myFunction to return a string, since it is typed as such. But it returns undefined.

This comes from the default value myConstant not being defined at the point where the function is called. This should either be an error (preferably), or myArgument should be forced to be typed to string | undefined (weird).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment