database praten Mutate references Create references Iterate lists Throw Exceptions Return values Een 'HTTP request' maken Een bestand uitlezen Naar een bestand schrijven
references Create references Iterate lists Throw Exceptions Return values Een 'HTTP request' maken Een bestand uitlezen Naar een bestand schrijven Met een database praten
ending return statement and return type does not include 'undefined' enum Countries { Belgium, Brazil } // Input set enum PaymentMethod { Bancontact, Visa, Mastercard } // Output set const FavoritePaymentMethod = (country: Countries): PaymentMethod => switch(country) { case Countries.Belgium: return PaymentMethod.Bancontact; } }
LAND VERBONDEN MET EEN FACTUUR? FACTUUR? const toCountry = (invoice: Invoice): Countries => { if (invoice.CountryCode === 'BE') return Countries.Belgium; if (invoice.CountryCode === 'BR') return Countries.Brazil; return ???; }
LAND VERBONDEN MET EEN FACTUUR? FACTUUR? undefined const toCountry = (invoice: Invoice): Countries => { if (invoice.CountryCode === 'BE') return Countries.Belgium; if (invoice.CountryCode === 'BR') return Countries.Brazil; return ; }
LAND VERBONDEN MET EEN FACTUUR? FACTUUR? TypeScript error: Type 'undefined' is not assignable to type 'Countries' const toCountry = (invoice: Invoice): Countries => { if (invoice.CountryCode === 'BE') return Countries.Belgium; if (invoice.CountryCode === 'BR') return Countries.Brazil; return undefined; }
EEN FACTUUR? GEASSOCIEERD AAN EEN FACTUUR? TypeScript error: Argument of type 'Countries | undefined' is not assignable to parameter of type 'Countries'. Type 'undefined' is not assignable to type 'Countries'. FavoritePaymentMethod(country); const toFavoritePaymentMethod = (invoice: Invoice): PaymentMethod => { const country: Countries | undefined = toCountry(invoice); return }
=> { switch(val.tag) { case 'Eur': // Do something with eur return val.Value; case 'Real': // Do something with real return val.Value; } // TypeScript infers all cases have been handled } type Eur = { tag: 'Eur', Value: number } type Real = { tag: 'Real', Value: number } type Currency = Eur | Real