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
<section class="sample-app-content"> | |
<h1>Esempio Reactive Form</h1> | |
<form [formGroup]="formElement" (ngSubmit)="accedi()"> | |
<p> | |
<label>Email:</label> | |
<input type="text" formControlName="email"> | |
</p> | |
<p> | |
<label>Password:</label> | |
<input type="password" formControlName="password"> |
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
import {NgModule} from "@angular/core"; | |
import {ReactiveFormsModule} from "@angular/forms"; | |
@Component({...}) | |
export class App { } | |
@NgModule({ | |
declarations: [App], | |
imports: [BrowserModule, ReactiveFormsModule], | |
bootstrap: [App] |
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
let altezza: any = 1.82; | |
let altezzaMimmo = altezza as number; | |
console.log(typeof(altezzaMimmo)); // number |
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
// Esempio su un numero | |
let altezza: any = 1.82; | |
let altezzaMimmo = <number> altezza; | |
console.log(typeof(altezzaMimmo)); // number | |
// Esempio su un oggetto | |
// Non corretto | |
let mimmo = {}; |
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 generaErrore(messaggio: string): never { | |
throw new Error(messaggio); | |
} | |
function elabora(): never { | |
while (true) { | |
console.log('Elaboro ed elaboro senza mai fermarmi.'); | |
} | |
} |
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
let valore: any; | |
valore = true; // OK | |
valore = 42; // OK | |
valore = "Wow Mimmo"; // OK | |
valore = []; // OK | |
valore = {}; // OK | |
valore = Math.random; // OK | |
valore = null; // OK | |
valore = undefined; // OK |
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
type IntersezioneTipi1 = unknown & null; // null | |
type IntersezioneTipi2 = unknown & undefined; // undefined | |
type IntersezioneTipi3 = unknown & string; // string | |
type IntersezioneTipi4 = unknown & number[]; // number[] | |
type IntersezioneTipi5 = unknown & any; // any |
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
type UnioneTipi1 = unknown | null; // unknown | |
type UnioneTipi2 = unknown | undefined; // unknown | |
type UnioneTipi3 = unknown | string; // unknown | |
type UnioneTipi4 = unknown | number[]; // unknown | |
type UnioneTipi5 = unknown | any; // any |
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
const sconosciuta: unknown = "Ciao Mimmo"; | |
const testo: string = sconosciuta as string; | |
const altroTesto = testo.toUpperCase(); | |
console.log(altroTesto); // "CIAO MIMMO" | |
// Considera che TypeScript non esegue controlli speciali per assicurarsi che | |
// l'asserzione del tipo sia effettivamente valida. Il controllo del tipo presume che | |
// tu sappia cosa stai facendo e pensa che il tipo utilizzato sia quello corretto. |
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
let isStringArray = (sconosciuta: unknown): sconosciuta is string[] => { | |
return ( | |
Array.isArray(sconosciuta) && | |
sconosciuta.every(el => typeof el === "string") | |
); | |
} | |
console.log(isStringArray([2,3,4,'Mimmo','Giovanni'])); // false | |
console.log(isStringArray(['Mimmo','Sandra','Leonardo','Filippo','Susanna'])); // true |
NewerOlder