mirror of
https://github.com/jbranchaud/til
synced 2026-01-20 07:28:02 +00:00
Compare commits
2 Commits
0715b7099f
...
8336834161
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8336834161 | ||
|
|
61d148f0d8 |
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1211 TILs and counting..._
|
||||
_1213 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -1028,6 +1028,7 @@ _1211 TILs and counting..._
|
||||
- [Silence The Output Of A Ruby Statement In Pry](ruby/silence-the-output-of-a-ruby-statement-in-pry.md)
|
||||
- [Single And Double Quoted String Notation](ruby/single-and-double-quoted-string-notation.md)
|
||||
- [Skip Specific CVEs When Auditing Your Bundle](ruby/skip-specific-cves-when-auditing-your-bundle.md)
|
||||
- [Specify Dependencies For A Rake Task](ruby/specify-dependencies-for-a-rake-task.md)
|
||||
- [Squeeze Out The Extra Space](ruby/squeeze-out-the-extra-space.md)
|
||||
- [String Interpolation With Instance Variables](ruby/string-interpolation-with-instance-variables.md)
|
||||
- [Summing Collections](ruby/summing-collections.md)
|
||||
@@ -1117,6 +1118,7 @@ _1211 TILs and counting..._
|
||||
- [Add Types To An Object Destructuring](typescript/add-types-to-an-object-destructuring.md)
|
||||
- [Compiler Checks For Unused Params And Variables](typescript/compiler-checks-for-unused-params-and-variables.md)
|
||||
- [Extract Object Type Keys Into A Union Type](typescript/extract-object-type-keys-into-a-union-type.md)
|
||||
- [Extract Object Type Values Into A Union Type](typescript/extract-object-type-values-into-a-union-type.md)
|
||||
- [Interfaces With The Same Name Are Merged](typescript/interfaces-with-the-same-name-are-merged.md)
|
||||
- [Re-Export An Imported Type](typescript/re-export-an-imported-type.md)
|
||||
- [Type Narrowing With Similarly Shaped Objects](typescript/type-narrowing-with-similarly-shaped-objects.md)
|
||||
|
||||
37
ruby/specify-dependencies-for-a-rake-task.md
Normal file
37
ruby/specify-dependencies-for-a-rake-task.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Specify Dependencies For A Rake Task
|
||||
|
||||
Let's say you have rake task that performs some important business task. For
|
||||
instance, a book seller might want a task that can tell them the top selling
|
||||
books from a CSV report.
|
||||
|
||||
```ruby
|
||||
task :top_selling_books do
|
||||
# read in CSV and process for top selling books
|
||||
end
|
||||
```
|
||||
|
||||
This works great if the CSV file already exists on the machine from which this
|
||||
task is run. What if it isn't tho?
|
||||
|
||||
The CSV is a prerequesite for this task. We explicitly define it as a
|
||||
prerequisite using the task dependency syntax.
|
||||
|
||||
```ruby
|
||||
task :download_latest_book_sales_csv do
|
||||
# saves a CSV of book sales
|
||||
end
|
||||
|
||||
task top_selling_books: :download_latest_book_sales_csv do
|
||||
# read in CSV and process for top selling books
|
||||
end
|
||||
```
|
||||
|
||||
We can even define multiple task dependencies with an array.
|
||||
|
||||
```ruby
|
||||
task top_selling_books: [:download_latest_book_sales_csv, :clean_csv] do
|
||||
# read in CSV and process for top selling books
|
||||
end
|
||||
```
|
||||
|
||||
[source](https://subscription.packtpub.com/book/hardware_and_creative/9781783280773/1/ch01lvl1sec13/task-dependencies-prerequisites)
|
||||
54
typescript/extract-object-type-values-into-a-union-type.md
Normal file
54
typescript/extract-object-type-values-into-a-union-type.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Extract Object Type Values Into A Union Type
|
||||
|
||||
Let's say we have an object type like the following:
|
||||
|
||||
```typescript
|
||||
type GlobalReducerEvent = {
|
||||
ADD_TODO: {
|
||||
text: string
|
||||
}
|
||||
LOG_IN: {
|
||||
email: string
|
||||
}
|
||||
DELETE_TODO: {
|
||||
todo_id: number
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
We can use the [indexed access
|
||||
type](https://www.typescriptlang.org/docs/handbook/2/indexed-access-types.html)
|
||||
to access the value indexed at one the type keys. This works a lot like
|
||||
JavaScript's object access.
|
||||
|
||||
```typescript
|
||||
type AddTodoType = GlobalReducerEvent['ADD_TODO'];
|
||||
/*
|
||||
type AddTodoType = {
|
||||
text: string
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
Where it gets more interesting and differs from JavaScript's object access is
|
||||
when we do an indexed access of a union type.
|
||||
|
||||
```typescript
|
||||
type TypesForEvents = GlobalReducerEvent[keyof GlobalReducerEvent];
|
||||
/*
|
||||
type TypesForEvents = {
|
||||
text: string
|
||||
} | {
|
||||
email: string
|
||||
} | {
|
||||
todo_id: number
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
The result is a union of each of the values whose keys had matches in the
|
||||
union.
|
||||
|
||||
Where this gets more interesting and useful is when we use it as part of a
|
||||
mapped type like I explore in [Breaking Down a Complex Mapped
|
||||
Type](https://dev.to/jbranchaud/breaking-down-a-complex-mapped-type-in5).
|
||||
Reference in New Issue
Block a user