total-typescript / typescript-generics-workshop Goto Github PK
View Code? Open in Web Editor NEWInteractive tutorial on using generics in TypeScript
Home Page: https://totaltypescript.com
Interactive tutorial on using generics in TypeScript
Home Page: https://totaltypescript.com
When running npm install, it installs @types/chai. Because of this my IDE (webstorm) is using the chai declaration of expect (which does not have toEqual) instead of vitest types. Do we actually need to install those chai types? deleting them seems to fix the issue.
Hey,
Why did you need to cast config.events
to any
in this line? Can't TS infer the object?
BTW, great repo. Thanks! ๐
The solution here https://github.com/total-typescript/typescript-generics-workshop/blob/main/src/04-generics-advanced/19-generic-interfaces-with-functions.solution.ts gives a Typescript error even though it passes all the tests:
clone: <U>(transform: (elem: T | undefined) => U) => Cache<U>;
seems to fix the issue
The provided code in the video does not seem to be working.
If you take the code and paste it into Typescript playground (I have done it for you) - you will get a bunch of errors.
The solution is as following:
const fetchData = async <T>(url: string): Promise<T> => await fetch(url).then(resp => resp.json as T)
Hi,
I just spent 1h trying to solve working around partial inference problem and I decided to watch the solution.
I had the right approach to solve it however Matt didn't experience the same error I had in my local IDE.
The 2nd type argument of makeSelectors
have a default value {} in the repo which the code in Matt video doesn't.
Once I removed it from my code all the test pass.
thanks!
You have a comment in the 14.5-literal-inference.explainer.ts file:
// When returning the value only, it infers
// the literal type
const returnsValueOnly = <T>(t: T) => {
return t;
};
const result = returnsValueOnly("a");
// ^?
This explanation is a bit misleading. In your example, it returns literal type not because of how your function is declared but because of how it is called. In other words, it is returned literal because "a"
parameter is interpreted as literal.
For example, if you pre-declare the function's argument as let
the type of return value will be a string
:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.