Skip to content

Commit

Permalink
export ValidationError interface (#6885)
Browse files Browse the repository at this point in the history
* export ValidationError interface

* add symbol to ValidationError

* Update packages/kit/types/index.d.ts

* fucking whitespace

* unique interface

* only include exported declarations in docs

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Co-authored-by: Rich Harris <hello@rich-harris.dev>
  • Loading branch information
3 people committed Sep 21, 2022
1 parent 28d1b9e commit 2776f33
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/kit/scripts/extract-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ function get_types(code, statements) {

if (statements) {
for (const statement of statements) {
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) : undefined;

const export_modifier = modifiers?.find((modifier) => modifier.kind === 93);
if (!export_modifier) continue;

if (
ts.isClassDeclaration(statement) ||
ts.isInterfaceDeclaration(statement) ||
Expand Down
6 changes: 4 additions & 2 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
PrerenderOnErrorValue,
RequestOptions,
RouteDefinition,
TrailingSlash
TrailingSlash,
UniqueInterface
} from './private.js';
import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal.js';
import { HttpError, Redirect } from '../src/runtime/control.js';
Expand Down Expand Up @@ -52,7 +53,8 @@ type OptionalUnion<
> = U extends unknown ? { [P in Exclude<A, keyof U>]?: never } & U : never;

// Needs to be here, else ActionData will be resolved to unknown - probably because of "d.ts file imports .js file" in combination with allowJs
interface ValidationError<T extends Record<string, unknown> | undefined = undefined> {
export interface ValidationError<T extends Record<string, unknown> | undefined = undefined>
extends UniqueInterface {
status: number;
data: T;
}
Expand Down
9 changes: 9 additions & 0 deletions packages/kit/types/private.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,12 @@ export interface RouteSegment {
}

export type TrailingSlash = 'never' | 'always' | 'ignore';

/**
* This doesn't actually exist, it's a way to better distinguish the type
*/
declare const uniqueSymbol: unique symbol;

export interface UniqueInterface {
readonly [uniqueSymbol]: unknown;
}

0 comments on commit 2776f33

Please sign in to comment.