-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
interface JSON { | ||
/** | ||
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string. | ||
* @param value A JavaScript value, usually an object or array, to be converted. | ||
* @param replacer A function that transforms the results. | ||
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. | ||
*/ | ||
stringify<T = any>( | ||
value: T, | ||
replacer?: (this: any, key: string, value: any) => any, | ||
space?: string | number | ||
): undefined extends T ? string | undefined : string; | ||
/** | ||
* Converts a JavaScript value to a JavaScript Object Notation (JSON) string. | ||
* @param value A JavaScript value, usually an object or array, to be converted. | ||
* @param replacer An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified. | ||
* @param space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read. | ||
*/ | ||
stringify<T = any>( | ||
value: T, | ||
replacer?: (number | string)[] | null, | ||
space?: string | number | ||
): undefined extends T ? string | undefined : string; | ||
} |
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,27 @@ | ||
import { doNotExecute, Equal, Expect } from "./utils"; | ||
|
||
doNotExecute(() => { | ||
const result = JSON.stringify(undefined); | ||
type tests = [Expect<Equal<typeof result, string | undefined>>]; | ||
}); | ||
|
||
doNotExecute(() => { | ||
const result = JSON.stringify(5 as undefined | number); | ||
type tests = [Expect<Equal<typeof result, string | undefined>>]; | ||
}); | ||
|
||
doNotExecute(() => { | ||
const result = JSON.stringify(undefined as any); | ||
type tests = [Expect<Equal<typeof result, string | undefined>>]; | ||
}); | ||
|
||
doNotExecute(() => { | ||
const result = JSON.stringify(undefined as unknown); | ||
type tests = [Expect<Equal<typeof result, string | undefined>>]; | ||
}); | ||
|
||
doNotExecute(() => { | ||
const value: null | string | number | boolean | object | Array<any> = null; | ||
const result = JSON.stringify(value); | ||
type tests = [Expect<Equal<typeof result, string>>]; | ||
}); |