-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Assignability for Mark* utility types (#364)
* test: β add Debug * test: β add assignability checks * fix: π§ͺ MarkRequired * fix: π§ͺ MarkReadonly * test: π§ͺ testMarkWritable * fix: π§ͺ MarkWritable * ci: β remove TS@<4.5 support * feat: β add Prettify * docs: π Prettify * test: β remove edge cases for TS@<4.5 * refactor: π Debug => Prettify * docs: π changeset
- Loading branch information
Showing
19 changed files
with
257 additions
and
167 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"ts-essentials": major | ||
--- | ||
|
||
Fixed assignability of Mark\* utility types which required removing support of TypeScript@<4.5 |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import { ReadonlyKeys } from "../readonly-keys"; | ||
import { Writable } from "../writable"; | ||
|
||
export type MarkReadonly<Type, Keys extends keyof Type> = Type extends Type | ||
? Omit<Type, Keys> & Readonly<Pick<Type, Keys>> | ||
? Readonly<Type> & | ||
Writable<Pick<Type, Exclude<keyof Type, Keys | (Type extends object ? ReadonlyKeys<Type> : never)>>> | ||
: never; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
export type MarkRequired<Type, Keys extends keyof Type> = Type extends Type | ||
? Omit<Type, Keys> & Required<Pick<Type, Keys>> | ||
: never; | ||
export type MarkRequired<Type, Keys extends keyof Type> = Type extends Type ? Type & Required<Pick<Type, Keys>> : never; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { Writable } from "../writable"; | ||
import { WritableKeys } from "../writable-keys"; | ||
|
||
export type MarkWritable<Type, Keys extends keyof Type> = Type extends Type | ||
? Omit<Type, Keys> & Writable<Pick<Type, Keys>> | ||
? Readonly<Type> & Writable<Pick<Type, (Type extends object ? WritableKeys<Type> : never) | Keys>> | ||
: never; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
`Prettify<Type>` flattens type and makes it more readable on the hover in your IDE. | ||
|
||
It shows what properties are included in interfaces: | ||
|
||
```ts | ||
interface Name { | ||
first: string; | ||
second: string; | ||
} | ||
|
||
type NameOnly = Name; | ||
// ^? Name | ||
|
||
type FullName = Prettify<Name>; | ||
// ^? {first: string; second: string} | ||
``` | ||
|
||
It flattens intersections: | ||
|
||
```ts | ||
type Intersection = Name & { | ||
address: string; | ||
}; | ||
|
||
type IntersectionOnly = Intersection; | ||
// ^? Name & {address: string} | ||
|
||
type EverythingAboutPerson = Prettify<Intersection>; | ||
// ^? {first: string; second: string; address: string} | ||
``` | ||
|
||
TS Playground - https://tsplay.dev/m3d51W |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type Prettify<Type> = { | ||
[Key in keyof Type]: Type[Key]; | ||
} & {}; |
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
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
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
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
Oops, something went wrong.