-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add type definitions for Uint8Array
to/from base64 methods
#61696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dontwanttothink
wants to merge
7
commits into
microsoft:main
Choose a base branch
from
dontwanttothink:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2471626
Add type definitions for `Uint8Array` to/from base64 methods
dontwanttothink 09db85c
Update baselines
dontwanttothink d5f1e1c
Update script target features
dontwanttothink f720939
Add tests
dontwanttothink ed6539c
Fix typo
dontwanttothink 3f18d3c
Use method definitions and narrow down type
dontwanttothink a5df42d
Update baselines
dontwanttothink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
48 changes: 48 additions & 0 deletions
48
tests/baselines/reference/toFromHexBase64(target=es2024).errors.txt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
toFromHexBase64.ts(1,25): error TS2550: Property 'fromBase64' does not exist on type 'Uint8ArrayConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. | ||
toFromHexBase64.ts(2,25): error TS2550: Property 'fromBase64' does not exist on type 'Uint8ArrayConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. | ||
toFromHexBase64.ts(3,25): error TS2550: Property 'fromHex' does not exist on type 'Uint8ArrayConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. | ||
toFromHexBase64.ts(12,20): error TS2550: Property 'setFromBase64' does not exist on type 'Uint8Array<ArrayBuffer>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. | ||
toFromHexBase64.ts(13,20): error TS2550: Property 'setFromBase64' does not exist on type 'Uint8Array<ArrayBuffer>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. | ||
toFromHexBase64.ts(14,20): error TS2550: Property 'setFromBase64' does not exist on type 'Uint8Array<ArrayBuffer>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. | ||
toFromHexBase64.ts(20,20): error TS2550: Property 'setFromHex' does not exist on type 'Uint8Array<ArrayBuffer>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. | ||
|
||
|
||
==== toFromHexBase64.ts (7 errors) ==== | ||
const arr1 = Uint8Array.fromBase64("AAAAAA=="); | ||
~~~~~~~~~~ | ||
!!! error TS2550: Property 'fromBase64' does not exist on type 'Uint8ArrayConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. | ||
const arr2 = Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }); | ||
~~~~~~~~~~ | ||
!!! error TS2550: Property 'fromBase64' does not exist on type 'Uint8ArrayConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. | ||
const arr3 = Uint8Array.fromHex("000000"); | ||
~~~~~~~ | ||
!!! error TS2550: Property 'fromHex' does not exist on type 'Uint8ArrayConstructor'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. | ||
|
||
const encodedBase64_1 = arr1.toBase64(); | ||
const encodedBase64_2 = arr1.toBase64({ alphabet: "base64" }); | ||
const encodedBase64_3 = arr1.toBase64({ alphabet: "base64url", omitPadding: true }); | ||
|
||
const encodedHex_1 = arr1.toHex(); | ||
|
||
const target1 = new Uint8Array(10); | ||
const r1 = target1.setFromBase64("AAAAAA=="); | ||
~~~~~~~~~~~~~ | ||
!!! error TS2550: Property 'setFromBase64' does not exist on type 'Uint8Array<ArrayBuffer>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. | ||
const r2 = target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }); | ||
~~~~~~~~~~~~~ | ||
!!! error TS2550: Property 'setFromBase64' does not exist on type 'Uint8Array<ArrayBuffer>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. | ||
const r3 = target1.setFromBase64("AAAAAA", { | ||
~~~~~~~~~~~~~ | ||
!!! error TS2550: Property 'setFromBase64' does not exist on type 'Uint8Array<ArrayBuffer>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. | ||
alphabet: "base64url", | ||
lastChunkHandling: "stop-before-partial" | ||
}); | ||
|
||
const target2 = new Uint8Array(10); | ||
const r4 = target2.setFromHex("000000"); | ||
~~~~~~~~~~ | ||
!!! error TS2550: Property 'setFromHex' does not exist on type 'Uint8Array<ArrayBuffer>'. Do you need to change your target library? Try changing the 'lib' compiler option to 'esnext' or later. | ||
|
||
const totalWritten = r1.written + r2.written + r3.written + r4.written; | ||
const totalRead = r1.read + r2.read + r3.read + r4.read; | ||
|
47 changes: 47 additions & 0 deletions
47
tests/baselines/reference/toFromHexBase64(target=es2024).js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//// [tests/cases/conformance/esnext/toFromHexBase64.ts] //// | ||
|
||
//// [toFromHexBase64.ts] | ||
const arr1 = Uint8Array.fromBase64("AAAAAA=="); | ||
const arr2 = Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }); | ||
const arr3 = Uint8Array.fromHex("000000"); | ||
|
||
const encodedBase64_1 = arr1.toBase64(); | ||
const encodedBase64_2 = arr1.toBase64({ alphabet: "base64" }); | ||
const encodedBase64_3 = arr1.toBase64({ alphabet: "base64url", omitPadding: true }); | ||
|
||
const encodedHex_1 = arr1.toHex(); | ||
|
||
const target1 = new Uint8Array(10); | ||
const r1 = target1.setFromBase64("AAAAAA=="); | ||
const r2 = target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }); | ||
const r3 = target1.setFromBase64("AAAAAA", { | ||
alphabet: "base64url", | ||
lastChunkHandling: "stop-before-partial" | ||
}); | ||
|
||
const target2 = new Uint8Array(10); | ||
const r4 = target2.setFromHex("000000"); | ||
|
||
const totalWritten = r1.written + r2.written + r3.written + r4.written; | ||
const totalRead = r1.read + r2.read + r3.read + r4.read; | ||
|
||
|
||
//// [toFromHexBase64.js] | ||
const arr1 = Uint8Array.fromBase64("AAAAAA=="); | ||
const arr2 = Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }); | ||
const arr3 = Uint8Array.fromHex("000000"); | ||
const encodedBase64_1 = arr1.toBase64(); | ||
const encodedBase64_2 = arr1.toBase64({ alphabet: "base64" }); | ||
const encodedBase64_3 = arr1.toBase64({ alphabet: "base64url", omitPadding: true }); | ||
const encodedHex_1 = arr1.toHex(); | ||
const target1 = new Uint8Array(10); | ||
const r1 = target1.setFromBase64("AAAAAA=="); | ||
const r2 = target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }); | ||
const r3 = target1.setFromBase64("AAAAAA", { | ||
alphabet: "base64url", | ||
lastChunkHandling: "stop-before-partial" | ||
}); | ||
const target2 = new Uint8Array(10); | ||
const r4 = target2.setFromHex("000000"); | ||
const totalWritten = r1.written + r2.written + r3.written + r4.written; | ||
const totalRead = r1.read + r2.read + r3.read + r4.read; |
82 changes: 82 additions & 0 deletions
82
tests/baselines/reference/toFromHexBase64(target=es2024).symbols
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
//// [tests/cases/conformance/esnext/toFromHexBase64.ts] //// | ||
|
||
=== toFromHexBase64.ts === | ||
const arr1 = Uint8Array.fromBase64("AAAAAA=="); | ||
>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) | ||
>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) | ||
|
||
const arr2 = Uint8Array.fromBase64("AAAAAA", { alphabet: "base64url" }); | ||
>arr2 : Symbol(arr2, Decl(toFromHexBase64.ts, 1, 5)) | ||
>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) | ||
>alphabet : Symbol(alphabet, Decl(toFromHexBase64.ts, 1, 46)) | ||
|
||
const arr3 = Uint8Array.fromHex("000000"); | ||
>arr3 : Symbol(arr3, Decl(toFromHexBase64.ts, 2, 5)) | ||
>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) | ||
|
||
const encodedBase64_1 = arr1.toBase64(); | ||
>encodedBase64_1 : Symbol(encodedBase64_1, Decl(toFromHexBase64.ts, 4, 5)) | ||
>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) | ||
|
||
const encodedBase64_2 = arr1.toBase64({ alphabet: "base64" }); | ||
>encodedBase64_2 : Symbol(encodedBase64_2, Decl(toFromHexBase64.ts, 5, 5)) | ||
>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) | ||
>alphabet : Symbol(alphabet, Decl(toFromHexBase64.ts, 5, 39)) | ||
|
||
const encodedBase64_3 = arr1.toBase64({ alphabet: "base64url", omitPadding: true }); | ||
>encodedBase64_3 : Symbol(encodedBase64_3, Decl(toFromHexBase64.ts, 6, 5)) | ||
>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) | ||
>alphabet : Symbol(alphabet, Decl(toFromHexBase64.ts, 6, 39)) | ||
>omitPadding : Symbol(omitPadding, Decl(toFromHexBase64.ts, 6, 62)) | ||
|
||
const encodedHex_1 = arr1.toHex(); | ||
>encodedHex_1 : Symbol(encodedHex_1, Decl(toFromHexBase64.ts, 8, 5)) | ||
>arr1 : Symbol(arr1, Decl(toFromHexBase64.ts, 0, 5)) | ||
|
||
const target1 = new Uint8Array(10); | ||
>target1 : Symbol(target1, Decl(toFromHexBase64.ts, 10, 5)) | ||
>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) | ||
|
||
const r1 = target1.setFromBase64("AAAAAA=="); | ||
>r1 : Symbol(r1, Decl(toFromHexBase64.ts, 11, 5)) | ||
>target1 : Symbol(target1, Decl(toFromHexBase64.ts, 10, 5)) | ||
|
||
const r2 = target1.setFromBase64("AAAAAA==", { lastChunkHandling: "strict" }); | ||
>r2 : Symbol(r2, Decl(toFromHexBase64.ts, 12, 5)) | ||
>target1 : Symbol(target1, Decl(toFromHexBase64.ts, 10, 5)) | ||
>lastChunkHandling : Symbol(lastChunkHandling, Decl(toFromHexBase64.ts, 12, 46)) | ||
|
||
const r3 = target1.setFromBase64("AAAAAA", { | ||
>r3 : Symbol(r3, Decl(toFromHexBase64.ts, 13, 5)) | ||
>target1 : Symbol(target1, Decl(toFromHexBase64.ts, 10, 5)) | ||
|
||
alphabet: "base64url", | ||
>alphabet : Symbol(alphabet, Decl(toFromHexBase64.ts, 13, 44)) | ||
|
||
lastChunkHandling: "stop-before-partial" | ||
>lastChunkHandling : Symbol(lastChunkHandling, Decl(toFromHexBase64.ts, 14, 24)) | ||
|
||
}); | ||
|
||
const target2 = new Uint8Array(10); | ||
>target2 : Symbol(target2, Decl(toFromHexBase64.ts, 18, 5)) | ||
>Uint8Array : Symbol(Uint8Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) | ||
|
||
const r4 = target2.setFromHex("000000"); | ||
>r4 : Symbol(r4, Decl(toFromHexBase64.ts, 19, 5)) | ||
>target2 : Symbol(target2, Decl(toFromHexBase64.ts, 18, 5)) | ||
|
||
const totalWritten = r1.written + r2.written + r3.written + r4.written; | ||
>totalWritten : Symbol(totalWritten, Decl(toFromHexBase64.ts, 21, 5)) | ||
>r1 : Symbol(r1, Decl(toFromHexBase64.ts, 11, 5)) | ||
>r2 : Symbol(r2, Decl(toFromHexBase64.ts, 12, 5)) | ||
>r3 : Symbol(r3, Decl(toFromHexBase64.ts, 13, 5)) | ||
>r4 : Symbol(r4, Decl(toFromHexBase64.ts, 19, 5)) | ||
|
||
const totalRead = r1.read + r2.read + r3.read + r4.read; | ||
>totalRead : Symbol(totalRead, Decl(toFromHexBase64.ts, 22, 5)) | ||
>r1 : Symbol(r1, Decl(toFromHexBase64.ts, 11, 5)) | ||
>r2 : Symbol(r2, Decl(toFromHexBase64.ts, 12, 5)) | ||
>r3 : Symbol(r3, Decl(toFromHexBase64.ts, 13, 5)) | ||
>r4 : Symbol(r4, Decl(toFromHexBase64.ts, 19, 5)) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.