-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add ImmutableHeaders * Test headers type inference * Add doc
- Loading branch information
Showing
10 changed files
with
129 additions
and
10 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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ImmutableHeaders } from "./headers"; | ||
|
||
{ | ||
type ContentType = | ||
| { "Content-Type": "application/json" } | ||
| { "content-type": "application/json" }; | ||
const headers = new Headers({ | ||
"Content-Type": "application/json", | ||
}) as unknown as ImmutableHeaders<ContentType & { optionalKey?: string }>; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const contentType: "application/json" = headers.get("Content-Type"); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const contentType2: "application/json" = headers.get("content-type"); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const hasContentType: true = headers.has("Content-Type"); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const optionalKey: boolean = headers.has("optionalKey"); | ||
} |
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,16 @@ | ||
import { AllKeys, AllValues, IsOptional } from "./type"; | ||
|
||
export interface ImmutableHeaders<H extends Record<string, string>> | ||
extends Omit<Headers, "set" | "append" | "delete"> { | ||
get<Name extends AllKeys<H>>(name: Name): AllValues<H, Name>; | ||
has<Name extends AllKeys<H>>( | ||
name: Name, | ||
): IsOptional<H, Name> extends true ? boolean : true; | ||
forEach( | ||
callbackfn: <Name extends AllKeys<H> & string>( | ||
value: AllValues<H, Name>, | ||
key: Name, | ||
parent: Headers, | ||
) => void, | ||
): void; | ||
} |
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
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