TypeScript Tutorial #11 - The DOM & Type Casting

  Рет қаралды 130,594

Net Ninja

Net Ninja

Күн бұрын

Пікірлер: 91
@priyandarshana4830
@priyandarshana4830 4 жыл бұрын
best full-stack developer i have ever seen
@ademineshat
@ademineshat 4 жыл бұрын
The best part "selectooooor" 😂 I love it 😍
@abdullahsuhaisk3694
@abdullahsuhaisk3694 4 жыл бұрын
When i watching your series , I can grab all thing with easly, Thanks a lot man !
@hojdog
@hojdog 4 жыл бұрын
My favorite way to access optional values is with optional chaining console.log(anchor?.href) logs href if anchor is defined, or just logs undefined
@miku4j
@miku4j 3 жыл бұрын
And it's a shortcut for console.log(anchor.href | undefined)
@george_bullock
@george_bullock 2 жыл бұрын
This is exactly the explanation I needed to drive this concept home. Thank you!
@Shakeel714
@Shakeel714 3 жыл бұрын
Thanks Shaun Pelling. This tutorial series is so helpful to follow along and learn TypeScript.
@artur838
@artur838 2 жыл бұрын
Your pronunciation of the word querySelector sounds very fun 🙂. Nice tutor, thanks
@PolskiArrow
@PolskiArrow Жыл бұрын
If you get an error in your browser while trying to print html element's properties in console *("Uncaught TypeError:* Cannot read properties of null (reading 'id')"), just move your script's link from to the end of field!
@ironcito1101
@ironcito1101 7 ай бұрын
You can also use so the script runs only after the HTML has loaded and available in the DOM.
@izzatullokanoatov370
@izzatullokanoatov370 4 жыл бұрын
4:17. Queryselectoooor :-).
@spellsaif
@spellsaif 4 жыл бұрын
always love hearing thaaaat!
@aerial_silks_sierra
@aerial_silks_sierra Ай бұрын
Lmao I was JUST hyperfixating on that 😂 he always pronounces at least one word like that. "Over HAeiRR" keeps me on the edge of my seat 😍
@zaph254
@zaph254 4 ай бұрын
He did the thing, he did the thing "selectoooooooor" I was specifically waiting for this, was not even concentrating, I was just waiting for this.
@NetNinja
@NetNinja 4 ай бұрын
Hahaha
@sanjaydhande6573
@sanjaydhande6573 4 жыл бұрын
Excellent! , best explanation for the series. Thanks !
@alexeyovriakh2450
@alexeyovriakh2450 3 жыл бұрын
Amazing tutorial!! Thank you so much for sharing your expertise with us!! :)
@somsubhra97
@somsubhra97 4 жыл бұрын
Hello Shaun sir,greetings from India.I have been watching your tutorials for an year now,they all are properly explained,much better than other courses I have taken which brings me back to this channel.I have a small request to make though,can you prep a small course with GraphQL Yoga and react apollo...
@adrean83
@adrean83 4 жыл бұрын
Hey took me a minute but I wasn't seeing the console logs straight away. Remember to change you script tag in index.html if you change the name of the ts file.
@Fleshlight_Reviewer
@Fleshlight_Reviewer 4 жыл бұрын
Can you dive into some ts react or ts node express server
@MrEvansjethro
@MrEvansjethro 2 жыл бұрын
Shaun, the real Ninja!
@runningsolution6154
@runningsolution6154 4 жыл бұрын
Thank you for the series!
@bobbysingh99
@bobbysingh99 4 жыл бұрын
Hey, any chance you would do a Typescript and React tutorial? Would be awesome!
@NetNinja
@NetNinja 4 жыл бұрын
At some point, yeah. Not just yet though!
@omemester6985
@omemester6985 4 жыл бұрын
@@NetNinja Yes please!
@dev_jeongdaeri
@dev_jeongdaeri 4 жыл бұрын
Awesome man 😎 👏👏👏💪
@aniketbhalla1521
@aniketbhalla1521 3 жыл бұрын
I want to be sure for this, we're using typescript predefined interfaces, in lib.something.d.ts, as object's type because interface knows all that's object's defined methods & properties. So when we use interface as type then typescript checks interface, given as type, and doesn't show us errors because those are for sure implemented in that object. Correct me if I'm wrong.
@dyunior
@dyunior 4 жыл бұрын
dang!, just learned that typeof number when its color blue in the console. :D
@bushigi5913
@bushigi5913 2 жыл бұрын
I love this chapter!
@seanbenediqueauditor3947
@seanbenediqueauditor3947 Жыл бұрын
Thanks for this, man. Real good!
@Jose-fr6lp
@Jose-fr6lp 4 жыл бұрын
I did not know about valueAsNumber 🤯
@hiteshj2110
@hiteshj2110 4 жыл бұрын
Selectooooooahhhhh ❤️
@MichaelSalo
@MichaelSalo 2 жыл бұрын
valueAsNumber is a new one for me
@DodaGarcia
@DodaGarcia Жыл бұрын
Instead of the type casting would it have worked using a regular TypeScript signature on the variable assignment? For example: const form: HTMLFormElement = document.querySelector('.new-item-form')
@ruchiii75
@ruchiii75 Жыл бұрын
when would you use as vs colon for typecasting?
@harshkulkarni9478
@harshkulkarni9478 3 жыл бұрын
If we're unsure whether anchor.href exists or not, wouldnt an easier way of checking be with 'anchor?.href' instead of a tedious for loop, this way we also wouldnt have to explicitly tell the compiler that we know it exists for sure
@naasim
@naasim 4 жыл бұрын
With the new optional chaining operator, here's another way: console.log(anchor?.href);
@Jason-uv5tm
@Jason-uv5tm 3 жыл бұрын
Is there a reason why you wouldn't want to use an exclamation mark (in this example, and others)?
@AliShokor-j1p
@AliShokor-j1p 2 ай бұрын
bro you are the best
@Nikiteshsingh
@Nikiteshsingh Жыл бұрын
Can we also use optional chaining here? something like "console.log(anchor?.href)"
@josbexerr5166
@josbexerr5166 3 жыл бұрын
Gran curso Ninja.....gracias
@shreyasjejurkar1233
@shreyasjejurkar1233 4 жыл бұрын
C# + JavaScript = Typescript
@insteresting
@insteresting 10 ай бұрын
Nice tutorial, Shaun! Love your accent by the way.. At 07:20, I wonder why TypeScript doesn't complain about using "type" as a variable name, since it is a reserved keyword..
@RichardBagnall1
@RichardBagnall1 Ай бұрын
What if you use document.querySelector('form.new-item-form')? Does TyepeS cript infer HTMLFormElement?
@shadmanmartinpiyal4057
@shadmanmartinpiyal4057 4 жыл бұрын
Hey gang.. you can also extract the form info by e.currentTarget.type.value and so on.....
@himbary
@himbary 4 жыл бұрын
TS is just
@farouktouil5036
@farouktouil5036 3 жыл бұрын
Hi, and thank you for the tutorial, I have a question How can I access a checkbox value in this form, I have tried but the typescript camplained about the value.
@shakilkhanprogrammer
@shakilkhanprogrammer 4 жыл бұрын
When I hover on the document object its shows me this error Cannot find the name 'document'. Do you need to change your target library? Try changing the `lib` compiler option to include 'dom'.ts(2584)
@Argha252
@Argha252 4 жыл бұрын
Hey there! I had the same issue. Here's what I did: Go to the vscode settings page > search for typescript:tsdk > click on change settings.json > there should be a json key for "typescript.tsdk" > paste this value "/npm_modules/typescript/lib". Hope this helps! :D
@ronit8067
@ronit8067 4 жыл бұрын
how is the Add button triggering this event? don't we have to assign a event listener to the button for this first? I don't get that part.
@pashabiceps95
@pashabiceps95 4 жыл бұрын
button is by default has type "submit", this means that it will trigger submit event of the parent form
@learningit2572
@learningit2572 2 жыл бұрын
Amauzing teacher cool tutorial!
@NetNinja
@NetNinja 2 жыл бұрын
Thanks!
@jonasd2860
@jonasd2860 3 жыл бұрын
Good job
@drewstifler1440
@drewstifler1440 4 жыл бұрын
almost 10k views with no dislikes!
@Bencia_blindDev
@Bencia_blindDev Жыл бұрын
dude, your ways of speaking is so funny~ huhhuh, "querySELECTOR~~~~~" lesson#13 4:15
@rikilamadrid
@rikilamadrid 4 жыл бұрын
For me my intellisense stopped working. document has a squiggly red line and when i hover it says: Cannot find name 'document'. Do you need to change your target library? Try changing the `lib` compiler option to include 'dom'.ts(2584)
@papesldjnsjkfjsn
@papesldjnsjkfjsn 3 жыл бұрын
you prob found the solution but for others it's a problem with the tsconfig, you need to include "dom" in the the lib compliler options
@papesldjnsjkfjsn
@papesldjnsjkfjsn 3 жыл бұрын
actually if you are setting the target to es3 you need to include: "lib": [ "DOM", "DOM.Iterable", "ScriptHost", "ES2015" ] for ts to know the main js functions and objects, otherwise it won't know anything about document or the console...
@rikilamadrid
@rikilamadrid 3 жыл бұрын
@@papesldjnsjkfjsn Thank you so much. I cant remember well if I did. I will def try this. I appreciate you taking the time and posting, thanks!
@ibrahimkholil6262
@ibrahimkholil6262 4 жыл бұрын
Hello everyone! Recently i'm working with redux. But i am not getting one thing and that is i created a store and reducers and dispatching an action and then state gets change and i am subscribed to the store with a callback which gets called on state change now in this callback i put in a render method which will re-render my UI but my question is what if i have multiple section in my UI suppose i have a Todo list and Movie List those two are different module depends on different data and if Todo list gets updated i have to re render the whole UI again cause i subscribed to store with render method and render method take the state and basically rerender the whole UI again in this case i just updated Todo list what i want is to just rerender UI part related to Todo list not Movie list. But i can not do that cause i am subscribed to store with render method and that method basically rerender the whole UI. Now how can i only rerender specific part of UI? Do i need to create two store? One for Todo one for Movie then does redux core principle works here cause their is not single source of truth where i have two store that means two state. Or am i getting it wrong? One more thing i am not using any UI library instead vanilla Javascript. Off topic but need help
@VishalSharma-rn7mt
@VishalSharma-rn7mt 2 жыл бұрын
Awesome
@bmeghani88
@bmeghani88 3 жыл бұрын
Does anyone know why it doesn't work the first time round with the event "submit". I had to change it to 'click' and then back to 'submit', then it worked?
@henrymatola592
@henrymatola592 2 жыл бұрын
Putting a question mark before .href is also working. 👇👇 console.log(data?.href);
@ridl27
@ridl27 4 жыл бұрын
ty vm ;)
@jeffinj7707
@jeffinj7707 4 жыл бұрын
Great
@mohammadmousavi6046
@mohammadmousavi6046 4 жыл бұрын
What the font editor ???
@jssecrets
@jssecrets 3 жыл бұрын
super!
@narasimhasriharshakanduri3325
@narasimhasriharshakanduri3325 4 жыл бұрын
How does typescript know about HTML elements???. The answer is ther is afile called lib/lib.dom.d.ts (github.com/microsoft/TypeScript/blob/master/lib/lib.dom.d.ts#L8208) . so typescript is using this details so that it can give out the errors and help us code better. In case we don't mention the tag a generic will be inferred instead of the particular element. The entire video is about casting the variable types so that we can catch the errors before the runtime
@sriramiyer9840
@sriramiyer9840 3 жыл бұрын
what is the syntax at 2:43 called?? the exclamation in querySelector('a')!. where can i find the docs for it? could someone please link to it if possible
@sriramiyer9840
@sriramiyer9840 3 жыл бұрын
ok, I found it. its called a "non-null assertion operator": www.typescriptlang.org/docs/handbook/release-notes/typescript-2-0.html#non-null-assertion-operator
@xxapoloxx
@xxapoloxx 3 жыл бұрын
What about radiobuttons?
@kelvin513
@kelvin513 4 жыл бұрын
7:37 even when i explicitly use 'select#type' in the querySelectoooor, TypeScript still saying it is a normal Element
@Nexus-rt1bm
@Nexus-rt1bm 4 жыл бұрын
Yeah, I don't get it either
@삶은계란-c2t
@삶은계란-c2t 3 жыл бұрын
4:15 Well, sensei...
@Jason-uv5tm
@Jason-uv5tm 3 жыл бұрын
at 7:08, you made a variable called type. But type is a typescript keyword. Are you sure doing that is safe?
@alisiraj2100
@alisiraj2100 4 жыл бұрын
AI tutorial plz
@unknownworld9815
@unknownworld9815 Жыл бұрын
query seeleectaur
@rodyguzman9654
@rodyguzman9654 4 жыл бұрын
FYI outdated info regarding the exclamation mark, it is or it will be deprecated in favor of optional chaining. Nice work on the series though!
@chiboreache
@chiboreache 4 жыл бұрын
that's why you should use Vue -_-
@ARZ10198
@ARZ10198 4 жыл бұрын
what's the most popular library angular , react or vue im a beginner and i know how to work with html ,css , bootstrap , JavaScript but now im confused what to learn now jQuery , node js or JavaScript libraries?
@mr.actapus4069
@mr.actapus4069 4 жыл бұрын
@@ARZ10198 learn Vue, does not matter which is popular, what matters is speed and quality, and also boostrap is bad
@mr.actapus4069
@mr.actapus4069 4 жыл бұрын
@Tigran Khachaturian yeah of course
@programmer4047
@programmer4047 4 жыл бұрын
😎
@jaayaustin336
@jaayaustin336 4 жыл бұрын
Swifttttttt
@programerz
@programerz 6 ай бұрын
this tutorial is not mobile friendly and the fonts are Small
@ajaymishra1511
@ajaymishra1511 Ай бұрын
didnt knew we can do .valueAsNumber
@interviews-land
@interviews-land 2 жыл бұрын
We can also use like this - console.log(ankor?.href) - still we will not get an error
TypeScript Tutorial #12 - Classes
8:47
Net Ninja
Рет қаралды 140 М.
Why use Type and not Interface in TypeScript
14:12
ByteGrad
Рет қаралды 214 М.
Perfect Pitch Challenge? Easy! 🎤😎| Free Fire Official
00:13
Garena Free Fire Global
Рет қаралды 91 МЛН
Ice Cream or Surprise Trip Around the World?
00:31
Hungry FAM
Рет қаралды 16 МЛН
Learn DOM Manipulation In 18 Minutes
18:37
Web Dev Simplified
Рет қаралды 1 МЛН
Enums considered harmful
9:23
Matt Pocock
Рет қаралды 212 М.
Learn JavaScript DOM Manipulation - Tutorial for Beginners
37:14
Beau Carnes
Рет қаралды 15 М.
Typescript Generics Tutorial
21:56
Ben Awad
Рет қаралды 219 М.
TypeScript Tutorial #10 - Function Signatures
7:46
Net Ninja
Рет қаралды 115 М.
TypeScript Interfaces vs Types
13:59
Harry Wolff
Рет қаралды 88 М.
any vs unknown vs never: TypeScript demystified
8:01
Andrew Burgess
Рет қаралды 24 М.
7 Awesome TypeScript Types You Should Know
8:57
Josh tried coding
Рет қаралды 88 М.