Comments (7)
Comment by Viacheslav Dobromyslov (viacheslavdobromyslov) on 2020-08-13 06:12:
Thank you for these examples. I want to add just one small note: els.map(el => '' + el)
is not a good way to convert number to string. ESlint will mark it as an error.
from effective-typescript.
Comment by danvdk on 2020-08-14 10:38:
Are you referring to the no-implicit-coercions
rule? The argument against '' + x
for string coercion there is entirely stylistic. Error and "not a good way" seem a bit strong for a matter of style.
from effective-typescript.
Comment by Zackery Zing (zackeryzing) on 2020-08-14 02:59:
In my linting rules, I always force functions to have a return type. I think in an article like this it is useful to have return types on all functions so there is no missing information.
from effective-typescript.
Comment by danvdk on 2020-08-14 07:35:
What Iβd really like is to have mouseover in the code snippets on the blog to see the inferred type, just like in your editor. I know some people (and some linters) insist on annotating all return types, but I do not.
from effective-typescript.
Comment by Romain Deneau (romain_deneau) on 2020-08-18 04:22:
Useful rule, nicely explained in this article π
I suggest to rename it "The Golden Rule of Generic Functions", because it's about functions, not all generic types - see basic counter example: in this generic type, type WithValue<t> = { value: T }
, T
appears only once.
from effective-typescript.
Comment by Vincent Jaubert (vincentjaubert) on 2021-05-16 05:14:
This is indeed pure gold, thank you.
from effective-typescript.
Comment by ThomasBurleson on 2021-12-07 11:32:
I really enjoyed reading this. Very important heuristics.
from effective-typescript.
Related Issues (20)
- The Seven Sources of Unsoundness in TypeScript HOT 6
- In defense of interface: Using declaration merging to disable bad parts HOT 4
- Suspected error in Item 25: Use async Functions Instead of Callbacks for Asynchronous Code HOT 1
- Exclusive Or and the Optional never Trick HOT 3
- The `cacheLast` function is not implemented as expected HOT 1
- The display of types HOT 4
- Translation
- A new way to test types HOT 2
- Generic Tips Part 1: Use Classes and Currying to create new inference sites HOT 4
- What's TypeScript compiling? Use a treemap to find out. HOT 1
- All I Want for Christmas Is⦠These Seven TypeScript Improvements HOT 17
- Use typed identity functions to guide type inference HOT 1
- A TypeScript Perspective on Go: the 2021 Advent of Code HOT 2
- Wrong sentence in page 72? HOT 4
- TypeScript and SQL: Six Ways to Bridge the Divide HOT 3
- Welcome to Effective TypeScript!
- The Saga of the Closure Compiler, and Why TypeScript Won HOT 1
- Unionize and Objectify: A Trick for Applying Conditional Types to Objects HOT 1
- The Hidden Side of Type Predicates HOT 1
- The Making of a TypeScript Feature: Inferring Type Predicates HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from effective-typescript.