typescript-book
typescript-book copied to clipboard
Class Example in Page "Interface"
Hey Basarat,
I'm reading the secsion Interface of the book. And decided to copy & past some snippet into typescript Playground. I've find that your code may not designed to be copyAndPastable. (See this result)
As a beginner for class
in Javascript, I belive here I may initialize x
and y
in the constructure. So what's your purpose here? Prefer a concise expression as exist on the book or others?
BTW: Awesome book really! I'm sure I will buy you something after I slowly finish my reading in the new future! 🌹 I'm pretty sure I've been your fans now 💘
Cheers
Su Gao
Hi @basarat ,
Since I'm really new in typescript. So it's a little hard for me to dealing with code snippets that can't run out of the box. Besides this "Issue" above. I've figured out some others like in section Callable snippets about Newable
.
Because I know this book's topic is something that let people "deep dive". So the audience may not persons like me. Feel free to close this issue, and I'll know what I found like this one is not treated as issue on your side. And I will stop going on report them. If you do think these can be treated as issues, I'll be more then happy to try to make PRs if I got answers.
Big thanks again for your effort put in this book! :rose: :rose: :rose:
There are still some questions / possible small issues comes across these days. Since @basarat still not take response to my Issue ticket. So please allow me to point out another one here:
In Chapter Exception Handling there is a example in secsion "You don't have to throw an error" as follow:
function myFunction (callback: (e?: Error)) {
doSomethingAsync(function () {
if (somethingWrong) {
callback(new Error('This is my error'))
} else {
callback();
}
});
}
I think variable somethingWrong
should be the parameter of the nested anonym function. So it may looks clearer if put it this way:
function myFunction (callback: (e?: Error)) {
doSomethingAsync(function (somethingWrong:any) {
if (somethingWrong) {
callback(new Error('This is my error'))
} else {
callback();
}
});
}