This file contains 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
/** | |
* Toggles class based on media query breakpoint activation. | |
* Depends on @angular/flex-layout | |
* Usage: | |
* <span | |
* class="green" | |
* class.xs="my-xs-class" | |
* class.sm="my-sm-class" | |
* class.md="my-md-class" | |
* class.lg="my-lg-class"> |
This file contains 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
let myBool = false; // Inferred boolean type | |
myBool = 1; // Error: Type '1' is not assignable to type 'boolean'. | |
let myBool2 = true; | |
myBool2 + 5 // Error: Operator '+' cannot be applied to types 'true' and '5'. |
This file contains 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
const userService = new HttpService<User>(); | |
const user = { id: 1, name: '' }; | |
userService.save(user) // user type is inferred to be User | |
.then(resp => { // resp type is inferred to be HttpResponse | |
console.log(resp.data.name); // resp.data is inferred to be User | |
}); |
This file contains 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
export type Url = string; | |
export interface HttpResponse<T> { | |
data: T; | |
} | |
export type PromisedHttpResponse<T> = Promise<HttpResponse<T>>; | |
export class HttpService<T> { | |
save(url: Url, data: T): PromisedHttpResponse<T> { | |
return Promise.resolve({data}); | |
}; | |
} |
This file contains 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
// The compiler has the --strictNullChecks flag set | |
let cannotBeNull = "I can't be null nor undefined"; | |
cannotBeNull = null; // error, 'null' is not assignable to 'string' | |
cannotBeNull = undefined; // error, 'undefined' is not assignable to 'string' | |
let nullable: string | null = "I can be null but not undefined"; | |
nullable = null; | |
nullable = undefined; // error, 'undefined' is not assignable to 'string | null' |
This file contains 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
/** | |
* Reverse a list in one expression, without using Array.reverse() | |
*/ | |
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
.reduce( | |
(acc, val) => [val, ...acc], | |
[] | |
); |
This file contains 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
module Main exposing (..) | |
import Html exposing (..) | |
sayHello user = | |
"Hello " ++ user.name ++ "!" | |
userRecord = |
This file contains 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
module Counter exposing (..) | |
import Html exposing (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (..) | |
programParams = | |
{ model = modelo | |
, view = vista |
This file contains 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
module Counter exposing (..) | |
import Html exposing (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (..) | |
programParams = | |
{ model = modelo | |
, view = vista |
This file contains 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
-- https://ellie-app.com/fMXwpzt7va1/1 | |
module MouseCoordinates exposing (..) | |
import Html exposing (Html, div, text, program) | |
import Html.Attributes exposing (style) | |
import Html.Events exposing (on) | |
import Json.Decode as Decode exposing (Decoder, map2, at, int) | |
-- MODEL |
OlderNewer