Open utterances-bot opened 1 year ago
Thanks for the post, Dmitri. TS is still a mystery to me. 😅
Quick question, right at the beginning there's this code example:
type Sum = (a: number, b: number) => number
// Assign to variable
const sum1: Sum = function(a: number, b: number): number { return a + b } // OK
Would I define a function type and(!) add type definitions inline or should I choose one over the other? It's seems like duplicated type definitions to me. 🤔
Thanks for the post, Dmitri. TS is still a mystery to me. 😅
You're welcome @stefanjudis!
Would I define a function type and(!) add type definitions inline or should I choose one over the other? It's seems like duplicated type definitions to me. 🤔
Normally I'd use type inference and not duplicate the types. This example is just for demonstration.
Thanks! That makes sense. 🙇♂️
Great read. Worth mentioning object/array return types e.g.
const useScreenSize: () => { width: number; height: number; screen: BreakPoint; };
Hello Dmitri, great read you have here. I want to know if one can define the method types as optional using "?"
Understanding TypeScript Function Types: A Beginner's Guide
Are you struggling to understand TypeScript function types? Look no further! This comprehensive guide covers everything you need to know.
https://dmitripavlutin.com/typescript-function-type/