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
Jochem
Jochem2y ago
they're type annotations, and part of typescript
Aozen
Aozen2y ago
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
Jochem
Jochem2y ago
can you link an example? I'd honestly probably still call them type annotations, even if they're only in the documentation.
Aozen
Aozen2y ago
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
Jochem
Jochem2y ago
ok, well, I'd still call them type annotations 🙂
Aozen
Aozen2y ago
mmm i willcheck it getElementById(elementId: string): HTMLElement | null; the website has example like this
Aozen
Aozen2y ago
Jochem
Jochem2y ago
that means that the thing you pass in has to be a string, and you'll get either null or an HTMLElement back
Aozen
Aozen2y ago
how do i know and where do i find those html element or html element collection or nodelist example :
querySelectorAll<K extends keyof HTMLElementTagNameMap>(selectors: K): NodeListOf<HTMLElementTagNameMap[K]>;
querySelectorAll<K extends keyof SVGElementTagNameMap>(selectors: K): NodeListOf<SVGElementTagNameMap[K]>;
querySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
querySelectorAll<K extends keyof HTMLElementTagNameMap>(selectors: K): NodeListOf<HTMLElementTagNameMap[K]>;
querySelectorAll<K extends keyof SVGElementTagNameMap>(selectors: K): NodeListOf<SVGElementTagNameMap[K]>;
querySelectorAll<E extends Element = Element>(selectors: string): NodeListOf<E>;
querySelector<K extends keyof HTMLElementTagNameMap>(selectors: K): HTMLElementTagNameMap[K] | null;
querySelector<K extends keyof SVGElementTagNameMap>(selectors: K): SVGElementTagNameMap[K] | null;
querySelector<E extends Element = Element>(selectors: string): E | null;
querySelector<K extends keyof HTMLElementTagNameMap>(selectors: K): HTMLElementTagNameMap[K] | null;
querySelector<K extends keyof SVGElementTagNameMap>(selectors: K): SVGElementTagNameMap[K] | null;
querySelector<E extends Element = Element>(selectors: string): E | null;
in part 2 it returns HTMLElementTagNameMap and SVGElementTagNameMap
Jochem
Jochem2y ago
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement htmlelement is just a standard type, found that by searching DDG for HTMLElement mdn
Aozen
Aozen2y ago
DDG ?
Jochem
Jochem2y ago
same for the collection and nodelist duck duck go, alternative to google
Aozen
Aozen2y ago
oh okay is duckduck go good for programming searches? since i am noticing google is getting worse and worse daily
Jochem
Jochem2y ago
eh, it's fine sometimes better sometimes worse
Aozen
Aozen2y ago
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?
Jochem
Jochem2y ago
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
Aozen
Aozen2y ago
how do we find that element if i use typescript i think it leaves me no choice
Jochem
Jochem2y ago
typescript will complain at you and you can figure it out then just google it
Aozen
Aozen2y ago
ok okay XD thank you ❤️