anyone can help me find the mdn resource for return types? example is
function add(x: number, y: number): number {
return x + y;
}
let myAdd = function (x: number, y: number): number {
return x + y;
};
so basically i forgot what those were called type casting or type coercion or other
20 Replies
they're type annotations, and part of typescript
mmm let me check 1moment
when it says for example the function should return an html collection or something like that
which gave me hard times when i started angular
is this close to type annotations
can you link an example?
I'd honestly probably still call them type annotations, even if they're only in the documentation.
sadly no since last time i tried it was a year ago ( but was thing i struggled with the most)
that is why i asked here
ok, well, I'd still call them type annotations 🙂
Documentation - DOM Manipulation
Using the DOM with TypeScript
mmm i willcheck it
getElementById(elementId: string): HTMLElement | null;
the website has example like this
that means that the thing you pass in has to be a string, and you'll get either
null
or an HTMLElement
backhow do i know and where do i find those
html element or html element collection
or nodelist
example :
in part 2 it returns HTMLElementTagNameMap
and SVGElementTagNameMap
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
htmlelement is just a standard type, found that by searching DDG for
HTMLElement mdn
DDG ?
same for the collection and nodelist
duck duck go, alternative to google
oh okay
is duckduck go good for programming searches?
since i am noticing google is getting worse and worse daily
eh, it's fine
sometimes better sometimes worse
thank you ❤️
so how do i know all of the elements of that api?
so many elements other than HTMLElement
how do people know what is needed and when?
I just kinda wing it
most of the time the distinction doesn't matter
and vanilla javascript barely cares about types anyway
an HTMLFormElement will have a few extra properties, but it'll still have the HTMLElement ones as well
mostly just don't worry about them too much until you run into a problem
how do we find that element
if i use typescript i think it leaves me no choice
typescript will complain at you and you can figure it out then
just google it
ok
okay XD
thank you ❤️