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
Show hidden characters
{ | |
"compilerOptions": { | |
"target": "es6", | |
"module": "commonjs", | |
"lib": ["dom", "es6", "es2017", "esnext.asynciterable"], | |
"sourceMap": true, | |
"outDir": "./dist", | |
"moduleResolution": "node", | |
"removeComments": true, | |
"noImplicitAny": true, |
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
// Define a book type | |
type Book = { | |
title: string; | |
genre: string; | |
publicationYear: number; | |
}; | |
// Define a list of types | |
const listOfBooks: Book[] = [ | |
{ |
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
// Define a book type | |
type Book = { | |
title: string; | |
genre: string; | |
publicationYear: number; | |
}; | |
// Define a list of types | |
const listOfBooks: Book[] = [ | |
{title: 'Dragon Of The Titans', genre: 'fantasy', publicationYear: 1992}, |
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
// Let's define our valueToFilter type | |
const filterArrayByValue = <T, P extends keyof T>( | |
items: T[], | |
propertyName: P, | |
valueToFilter: T[P] //Partial<T> | |
): T[] => { | |
return items.filter(item =>item[propertyName] === valueToFilter); | |
}; |
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
type Book = { | |
title: string; | |
genre: string; | |
publicationYear: number; | |
}; | |
type Car = { | |
modelName: string; | |
type: string; | |
price: number; |
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
// Add a new generic type P | |
const filterArrayByValue = <T, P extends keyof T>( | |
items: T[], | |
propertyName: P, | |
valueToFilter: string | |
): T[] => { | |
return items.filter(item =>item[propertyName] === valueToFilter); | |
}; |
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
// Add a new generic type T | |
const filterArrayByValue = <T>( | |
items: T[], | |
propertyName: string, | |
valueToFilter: string | |
): T[] => { | |
return items.filter(item =>item[propertyName] === valueToFilter); | |
}; |
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 * as React from "react"; | |
import { render } from "react-dom"; | |
import { SidebarProvider, useSidebarContext } from "./useSidebarContext"; | |
import { ChildComponent } from "./childComponent"; | |
export const App = () => { | |
const [isOpen] = useSidebarContext(); | |
return ( | |
<div> |
OlderNewer