| Create | Read | Update | |
|---|---|---|---|
| Object.freeze() | ❌ | ✅ | ❌ |
| Object.seal() | ❌ | ✅ | ✅ |
This file contains hidden or 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
| // Rebuilding Utility Types | |
| // T = Type; K = Keys; U = Union; | |
| // Nullable | |
| type MyNullable<T> = T | null; | |
| type MyNullableTest = MyNullable<🍓>; // MyNullableTest = 🍓 | null | |
| // Non-Nullable (filter != null | undefined) | |
| type MyNonNullable<T> = T extends null | undefined ? never : T; | |
| type MyNonNullableTest = MyNullable<🍊 | 🥝 | null | undefined> // MyNonNullableTest = 🍊 | 🥝 |
This file contains hidden or 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
| // keyof | |
| // creates a type based on provided obkect keys | |
| type Lusophone = keyof {Brasil: 🇧🇷, Angola: 🇦🇴, "Cape Verde": 🇨🇻} // Lusophone = "Brasil" | "Angola" | "Cape Verde" |
This file contains hidden or 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
| // Higher-Order Functions & Callback | |
| // ¹. A higher order function takes a function as a parameter. | |
| // ². A callback is a function (() => {...}) that is passed as an argument. | |
| const higherOrderFunction¹= (callback²) => { | |
| return callback(); | |
| } |
This file contains hidden or 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
| // Functional Instantiation | |
| // the weakness of this pattern is that whenever we create | |
| // a new person, we have to re-create all the methods in memory, | |
| // which is not cool.. | |
| function Person (name, energy) { | |
| let person = {} | |
| person.name = name | |
| person.energy = energy | |
| person.eat = function (amount) { |
This file contains hidden or 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
| // Default importing | |
| import Func from 'utils' | |
| // Entire content importing | |
| import * as Utils from 'utils' | |
| // Selective importing | |
| import {Func} from 'utils' | |
| // Selective importing with alias |
This file contains hidden or 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 CallbackProps = (...args: any[]) => any; | |
| const useCallback2 = <T extends CallbackProps>( | |
| y: T, | |
| dependencies: unknown[] | |
| ): T => { | |
| const [myState, setMyState] = useState<T>(() => y); | |
| useEffect(() => { | |
| setMyState(() => y); | |
| }, dependencies); | |
| return myState; |
OlderNewer