Skip to content

Commit

Permalink
improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchoz49 committed May 24, 2024
1 parent 21a19f6 commit 2f2655d
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 6 deletions.
22 changes: 22 additions & 0 deletions src/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,28 @@ export const write = async (path, opts = {}) => {
* @typedef {import('@sinclair/typebox').Static<T>} Static
*/
/**
* @typedef {{
* [Path in keyof typeof schema]: {
* [Method in keyof typeof schema[Path]]: {
* [Prop in keyof typeof schema[Path][Method]]: typeof schema[Path][Method][Prop] extends TSchema ?
* Static<typeof schema[Path][Method][Prop]> :
* undefined
* }
* }
* }} SchemaType
*/
/**
* @typedef {{
* [ComponentType in keyof typeof _components]: {
* [ComponentName in keyof typeof _components[ComponentType]]: typeof _components[ComponentType][ComponentName] extends TSchema ?
* Static<typeof _components[ComponentType][ComponentName]> :
* undefined
* }
* }} ComponentType
*/
/** @typedef {Json[]} JsonArray */
/** @typedef {{ [key: string | number]: Json }} JsonRecord */
/** @typedef {string} JsonString */
Expand Down
7 changes: 1 addition & 6 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* @template {import('@sinclair/typebox').TSchema} T
* @typedef {import('@sinclair/typebox').Static<T>} Static
*/

import test, { after } from 'node:test'
import assert from 'node:assert'
import { readFile, writeFile, mkdir } from 'node:fs/promises'
Expand Down Expand Up @@ -290,7 +285,7 @@ test('basic test', async () => {
const { data, error, clientError } = await postRoute(args)
assert.equal(error, undefined)
assert.equal(clientError, undefined)
expectTypeOf(data).toEqualTypeOf(/** @type {Static<typeof import('../tmp/schema.js')['schema']['/some-route/{id}']['POST']['data']>} */(args))
expectTypeOf(data).toEqualTypeOf(/** @type {import('../tmp/schema.js').SchemaType['/some-route/{id}']['POST']['data']} */(args))
})
})
})
Expand Down
22 changes: 22 additions & 0 deletions test/petstore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@
* @typedef {import('@sinclair/typebox').Static<T>} Static
*/

/**
* @typedef {{
* [Path in keyof typeof schema]: {
* [Method in keyof typeof schema[Path]]: {
* [Prop in keyof typeof schema[Path][Method]]: typeof schema[Path][Method][Prop] extends TSchema ?
* Static<typeof schema[Path][Method][Prop]> :
* undefined
* }
* }
* }} SchemaType
*/

/**
* @typedef {{
* [ComponentType in keyof typeof _components]: {
* [ComponentName in keyof typeof _components[ComponentType]]: typeof _components[ComponentType][ComponentName] extends TSchema ?
* Static<typeof _components[ComponentType][ComponentName]> :
* undefined
* }
* }} ComponentType
*/

/** @typedef {Json[]} JsonArray */
/** @typedef {{ [key: string | number]: Json }} JsonRecord */
/** @typedef {string} JsonString */
Expand Down
22 changes: 22 additions & 0 deletions test/schema.cjs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@
* @typedef {import('@sinclair/typebox').Static<T>} Static
*/

/**
* @typedef {{
* [Path in keyof typeof schema]: {
* [Method in keyof typeof schema[Path]]: {
* [Prop in keyof typeof schema[Path][Method]]: typeof schema[Path][Method][Prop] extends TSchema ?
* Static<typeof schema[Path][Method][Prop]> :
* undefined
* }
* }
* }} SchemaType
*/

/**
* @typedef {{
* [ComponentType in keyof typeof _components]: {
* [ComponentName in keyof typeof _components[ComponentType]]: typeof _components[ComponentType][ComponentName] extends TSchema ?
* Static<typeof _components[ComponentType][ComponentName]> :
* undefined
* }
* }} ComponentType
*/

/** @typedef {Json[]} JsonArray */
/** @typedef {{ [key: string | number]: Json }} JsonRecord */
/** @typedef {string} JsonString */
Expand Down
22 changes: 22 additions & 0 deletions test/schema.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@
* @typedef {import('@sinclair/typebox').Static<T>} Static
*/

/**
* @typedef {{
* [Path in keyof typeof schema]: {
* [Method in keyof typeof schema[Path]]: {
* [Prop in keyof typeof schema[Path][Method]]: typeof schema[Path][Method][Prop] extends TSchema ?
* Static<typeof schema[Path][Method][Prop]> :
* undefined
* }
* }
* }} SchemaType
*/

/**
* @typedef {{
* [ComponentType in keyof typeof _components]: {
* [ComponentName in keyof typeof _components[ComponentType]]: typeof _components[ComponentType][ComponentName] extends TSchema ?
* Static<typeof _components[ComponentType][ComponentName]> :
* undefined
* }
* }} ComponentType
*/

/** @typedef {Json[]} JsonArray */
/** @typedef {{ [key: string | number]: Json }} JsonRecord */
/** @typedef {string} JsonString */
Expand Down

0 comments on commit 2f2655d

Please sign in to comment.