-
-
Notifications
You must be signed in to change notification settings - Fork 546
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(types): `JSONParsed` supports interface and `Date` etc. * denoify * supports bigint as never * denoify
- Loading branch information
Showing
3 changed files
with
95 additions
and
6 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,71 @@ | ||
import type { Equal, Expect, JSONParsed } from './types' | ||
|
||
describe('JSONParsed', () => { | ||
enum SampleEnum { | ||
Value1 = 'value1', | ||
Value2 = 'value2', | ||
} | ||
|
||
interface Meta { | ||
metadata: { | ||
href: string | ||
sampleEnum: SampleEnum | ||
} | ||
} | ||
|
||
interface SampleInterface { | ||
someMeta: Meta | ||
} | ||
|
||
type SampleType = { | ||
someMeta: Meta | ||
} | ||
|
||
it('Should parse a complex type', () => { | ||
const sample: JSONParsed<SampleType> = { | ||
someMeta: { | ||
metadata: { | ||
href: '', | ||
sampleEnum: SampleEnum.Value1, | ||
}, | ||
}, | ||
} | ||
expectTypeOf(sample).toEqualTypeOf<SampleType>() | ||
}) | ||
|
||
it('Should parse a complex interface', () => { | ||
const sample: JSONParsed<SampleInterface> = { | ||
someMeta: { | ||
metadata: { | ||
href: '', | ||
sampleEnum: SampleEnum.Value1, | ||
}, | ||
}, | ||
} | ||
expectTypeOf(sample).toEqualTypeOf<SampleInterface>() | ||
}) | ||
|
||
it('Should convert Date to string', () => { | ||
type Post = { | ||
datetime: Date | ||
} | ||
type Expected = { | ||
datetime: string | ||
} | ||
type Actual = JSONParsed<Post> | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
type verify = Expect<Equal<Expected, Actual>> | ||
}) | ||
|
||
it('Should convert bigint to never', () => { | ||
type Post = { | ||
num: bigint | ||
} | ||
type Expected = { | ||
num: never | ||
} | ||
type Actual = JSONParsed<Post> | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
type verify = Expect<Equal<Expected, Actual>> | ||
}) | ||
}) |
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