This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface Noun { | |
id: string; | |
created?: number; | |
name: string; | |
} | |
export interface Character extends Noun { | |
gender: Gender; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myCharacter: Character = api.get<Character>(`/character/${characterId}`); | |
if(myCharacter.metadata.type === 'Hero') { | |
// this will blow up if there is no "metadata" property on the "myCharacter" object | |
// Cannot read property 'type' of undefined | |
} | |
if(myCharacter?.metadata?.type === 'Hero') { | |
// the optional chaining operator will default the entire expression to undefined | |
// if any property along the way is undefined. This condition will evaluate to false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare module 'exampleModule'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Could not find a declaration file for module 'exampleModule'. '.../node_modules/exampleModule.js' implicitly has an 'any' type. | |
Try `npm i --save-dev @types/exampleModule` if it exists or add a new declaration (.d.ts) file containing `declare module 'exampleModule';` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add(a: number, b: number): number { | |
/* | |
Let's assume there is a bunch of logic here which makes | |
the error message in this function less obvious | |
*/ | |
return 'a' + 'b'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
No overload matches this call. | |
Overload 1 of 2, '(actionCreator: ActionCreatorWithPayload<Partial<Character>, string>, reducer: CaseReducer<State, { payload: Partial<Character>; type: string; }>): ActionReducerMapBuilder<...>', gave the following error. | |
Type '(WritableDraft<Partial<Character>> | "123")[]' is not assignable to type 'WritableDraft<Partial<Character>>[]'. | |
Type 'WritableDraft<Partial<Character>> | "123"' is not assignable to type 'WritableDraft<Partial<Character>>'. | |
Type '"123"' has no properties in common with type 'WritableDraft<Partial<Character>>'. | |
Overload 2 of 2, '(type: string, reducer: CaseReducer<State, { payload: Partial<Character>; type: string; }>): ActionReducerMapBuilder<State>', gave the following error. | |
Argument of type 'ActionCreatorWithPayload<Partial<Character>, string>' is not assignable to parameter of type 'string'. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { useSelector } from "react-redux"; | |
import {selectCountFormatted} from './selectors' | |
export const Counter = () => { | |
const countFormattedAsDollars = useSelector(selectCountFormatted('$')); | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const selectCount = (state: RootState) => state.counter.value; | |
export const selectCountFormatted = | |
(formatter: "$" | "%") => (state: RootState) => | |
`${formatter === "$" ? "$" : ""}${selectCount(state)}${ | |
formatter === "%" ? "%" : "" | |
}`; | |
export const selectCountAndStatus = (state: RootState) => | |
`The current count is ${selectCount(state)} and the status is ${ | |
state.counter.status | |
}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const Counter = () => { | |
const count = useSelector((state: RootState) => state.counter.value) | |
return ( | |
<div> | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
CounterState, | |
decrement, | |
increment, | |
incrementByAmount, | |
testableCounterReducer, | |
} from "./testableCounterReducer"; | |
describe("testable counter reducer", () => { | |
const initialState: CounterState = { |
NewerOlder