Halcyon and on and on, part II

Halcyon and On and On and On and On and On and On and On and On and On

I like this song. 

It is the ending song to Mean Girls and the song at the beginning of the credits too and maybe even for all of the while credits. Regardless of whether it is for this reason or not, this song always makes me feel like I am having a happy ending.

Orange crested newt soft toy sitting in front of a white background. The newt is smiling.
Here is a picture of my newt, lol

Default Parameters

"If a parameter is assigned a default value, TypeScript will infer the variable type to be the same as the default value's type. (This is similar to how TypeScript infers the type of an initialised variable to be the same as the type of its initial value)."

"Parameters with default values don't need a ? after the name, since assigning a default value already implies that they're optional parameters".

Inferring Return Types

"TypeScript can also infer the types of values returned by functions. 

It does this by looking at the types of the values after a function's return statements."

I don't really understand how it is that this works, but I think it's also to do with the type that is assigned to any parameter that's used (but what if there is more than one parameter??!).

Explicit Return Types

You can state the return type of the function after the closing parentheses of the parameters. 

This also works with arrow functions.

It is cool and can be used for spotting errors and bugs in your code. 🐛

Void Return Type

Type annotations "make everything neat and aid in understanding or code."

Therefore "it is often preferred to use type annotations for functions, even when those functions don't return anything."

If there is no return value, then the return type is void

Interestingly when I tested it out this is the error that I got: A function whose declared type is neither 'void' nor 'any' must return a value.

Documentation Functions

Documenting using comments is common in Typescript, especially for functions. 
Here is an example:

/**
* YO
* WHAT'S UP
* HERE ARE SOME COMMENTS
* @param describes a parameter in the function
* @param sometimes functions have two or more parameters...
* @returns this comment can describe what the function returns...
*
*/

Comments

Popular posts from this blog

Hello World

Yosemite

Two Lines of Thought, Makes Me Wonder What I'm Missing