React Course - TypeScript - Props

  Рет қаралды 20,248

Techbase

Techbase

Күн бұрын

Пікірлер: 18
@jamesa.
@jamesa. 3 жыл бұрын
Thanks so much for this. I was having some issues and you really helped! I wish more people found this.
@TechbaseDev
@TechbaseDev 3 жыл бұрын
Really glad the video was helpful to you!
@Racools
@Racools 2 жыл бұрын
For some reason I needed to make headerText optional in the Addprops interface. Property 'headerText' is missing in type '{}' but required in type 'AppProps'.
@TechbaseDev
@TechbaseDev 2 жыл бұрын
You might have a small difference in your code compared to mine. Sometimes restarting the TypeScript server can get rid of some problems.
@myhanhnguyen5198
@myhanhnguyen5198 2 жыл бұрын
i have have same problem but can't fix it
@alexanderberglehner2736
@alexanderberglehner2736 2 жыл бұрын
you can do: [key: string]: string
@luanecarolineaquinocavalca1064
@luanecarolineaquinocavalca1064 2 жыл бұрын
thank you! very good explanation!
@mertcankose5079
@mertcankose5079 3 жыл бұрын
Thanks, it's really helped me
@hoyinli7462
@hoyinli7462 2 жыл бұрын
great video!
@douarmedouailislam1840
@douarmedouailislam1840 2 жыл бұрын
for some reason i can only use optional props if i dont add the ? it says : Property 'headerText' is missing in type '{}' but required in type 'AppProps'
@myhanhnguyen5198
@myhanhnguyen5198 2 жыл бұрын
i have same problem as wll :(
@tadakuniyasuda8214
@tadakuniyasuda8214 2 жыл бұрын
Did you guys find the solution for this?
@alexanderberglehner2736
@alexanderberglehner2736 2 жыл бұрын
you can do: [key: string]: string
@lanbuitan7208
@lanbuitan7208 3 жыл бұрын
thank for your video, why we not use props: Props and not type all property in interface to parameter
@TechbaseDev
@TechbaseDev 3 жыл бұрын
I'm not sure if I understand you correctly, so please correct me if I'm mistaken. It seems that you talk about so called "inline type annotation" (example: www.carlrippon.com/Different-ways-to-strongly-type-function-component-props-with-typescript/#:~:text=Inline,Perhaps). While this is definitely possible, I prefer and recommend a "type alias " (like we use in this video). Especially with a large amount of props "inline type annotation" can make your component look a bit messy. For me consistency is key in codebases and since you can never go wrong with "type aliases" I prefer the latter.
@simonjones90
@simonjones90 2 жыл бұрын
I fixed the error '"Property 'headerText' is missing in type '{}' but required in type 'AppProps'" by passing a property to the App component in both App.tsx and App.test.tsx so the code is like in both those files. Otherwise you're breaking the interface you've just defined as it's expecting a param to be passed but you're trying to render the App component without one.
@annaiustus9445
@annaiustus9445 2 жыл бұрын
Why did you use Interface instead of Type?
@TechbaseDev
@TechbaseDev 2 жыл бұрын
Based on new insights, I would now use types since they are more constrained: react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/basic_type_example/#:~:text=consider%20using%20type%20for%20your%20React%20Component%20Props%20and%20State%2C%20for%20consistency%20and%20because%20it%20is%20more%20constrained.
React Course - TypeScript - useState
11:20
Techbase
Рет қаралды 15 М.
React Course - TypeScript - Generic Components
8:18
Techbase
Рет қаралды 11 М.
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
React Course - State Management - Component Composition
8:16
Techbase
Рет қаралды 4,2 М.
React Course - TypeScript - Enums
10:24
Techbase
Рет қаралды 9 М.
Try Catch Error Handling With TypeScript
8:53
ByteGrad
Рет қаралды 9 М.
React Course - TypeScript - Context API
7:09
Techbase
Рет қаралды 14 М.
2,000 People Fight For $5,000,000
24:45
MrBeast
Рет қаралды 20 МЛН
Testing In React Tutorial - Jest and React Testing Library
21:28
React Course - TypeScript - Forms and Events
3:59
Techbase
Рет қаралды 20 М.
Google’s Quantum Chip: Did We Just Tap Into Parallel Universes?
9:34
SORAKA & Jhin vs BLITZCRANK & Varus (SUP) | 0/2/12 | KR Diamond | 14.24
23:17