@sveltejs/kit 1.0.0-next.484 → 1.0.0-next.486
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/core/sync/write_types/index.js +13 -8
- package/types/index.d.ts +15 -3
package/package.json
CHANGED
|
@@ -159,6 +159,9 @@ function update_types(config, routes, route) {
|
|
|
159
159
|
/** @type {string[]} */
|
|
160
160
|
const exports = [];
|
|
161
161
|
|
|
162
|
+
// add 'Expand' helper
|
|
163
|
+
// Makes sure a type is "repackaged" and therefore more readable
|
|
164
|
+
declarations.push('type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;');
|
|
162
165
|
declarations.push(
|
|
163
166
|
`type RouteParams = { ${route.names.map((param) => `${param}: string`).join('; ')} }`
|
|
164
167
|
);
|
|
@@ -278,7 +281,7 @@ function process_node(node, outdir, is_page, all_pages_have_load = true) {
|
|
|
278
281
|
written_proxies.push(`proxy${basename}`);
|
|
279
282
|
}
|
|
280
283
|
|
|
281
|
-
server_data = get_data_type(node.server, 'null', proxy);
|
|
284
|
+
server_data = get_data_type(node.server, 'null', proxy, true);
|
|
282
285
|
|
|
283
286
|
const parent_type = `${prefix}ServerParentData`;
|
|
284
287
|
|
|
@@ -305,7 +308,7 @@ function process_node(node, outdir, is_page, all_pages_have_load = true) {
|
|
|
305
308
|
? `./proxy${replace_ext_with_js(basename)}`
|
|
306
309
|
: path_to_original(outdir, node.server);
|
|
307
310
|
|
|
308
|
-
type = `Kit.AwaitedActions<typeof import('${from}').actions
|
|
311
|
+
type = `Expand<Kit.AwaitedActions<typeof import('${from}').actions>>`;
|
|
309
312
|
}
|
|
310
313
|
}
|
|
311
314
|
exports.push(`export type ActionData = ${type};`);
|
|
@@ -328,7 +331,7 @@ function process_node(node, outdir, is_page, all_pages_have_load = true) {
|
|
|
328
331
|
|
|
329
332
|
const type = get_data_type(node.shared, `${parent_type} & ${prefix}ServerData`, proxy);
|
|
330
333
|
|
|
331
|
-
data = `Omit<${parent_type}, keyof ${type}> & ${type}
|
|
334
|
+
data = `Expand<Omit<${parent_type}, keyof ${type}> & ${type}>`;
|
|
332
335
|
|
|
333
336
|
const output_data_shape =
|
|
334
337
|
!is_page && all_pages_have_load
|
|
@@ -340,9 +343,9 @@ function process_node(node, outdir, is_page, all_pages_have_load = true) {
|
|
|
340
343
|
|
|
341
344
|
exports.push(`export type ${prefix}LoadEvent = Parameters<${prefix}Load>[0];`);
|
|
342
345
|
} else if (server_data === 'null') {
|
|
343
|
-
data = parent_type
|
|
346
|
+
data = `Expand<${parent_type}>`;
|
|
344
347
|
} else {
|
|
345
|
-
data = `Omit<${parent_type}, keyof ${prefix}ServerData> & ${prefix}ServerData
|
|
348
|
+
data = `Expand<Omit<${parent_type}, keyof ${prefix}ServerData> & ${prefix}ServerData>`;
|
|
346
349
|
}
|
|
347
350
|
|
|
348
351
|
exports.push(`export type ${prefix}Data = ${data};`);
|
|
@@ -353,8 +356,9 @@ function process_node(node, outdir, is_page, all_pages_have_load = true) {
|
|
|
353
356
|
* @param {string} file_path
|
|
354
357
|
* @param {string} fallback
|
|
355
358
|
* @param {Proxy} proxy
|
|
359
|
+
* @param {boolean} expand
|
|
356
360
|
*/
|
|
357
|
-
function get_data_type(file_path, fallback, proxy) {
|
|
361
|
+
function get_data_type(file_path, fallback, proxy, expand = false) {
|
|
358
362
|
if (proxy) {
|
|
359
363
|
if (proxy.exports.includes('load')) {
|
|
360
364
|
// If the file wasn't tweaked, we can use the return type of the original file.
|
|
@@ -362,7 +366,8 @@ function process_node(node, outdir, is_page, all_pages_have_load = true) {
|
|
|
362
366
|
const from = proxy.modified
|
|
363
367
|
? `./proxy${replace_ext_with_js(path.basename(file_path))}`
|
|
364
368
|
: path_to_original(outdir, file_path);
|
|
365
|
-
|
|
369
|
+
const type = `Kit.AwaitedProperties<Awaited<ReturnType<typeof import('${from}').load>>>`;
|
|
370
|
+
return expand ? `Expand<${type}>` : type;
|
|
366
371
|
} else {
|
|
367
372
|
return fallback;
|
|
368
373
|
}
|
|
@@ -484,7 +489,7 @@ export function tweak_types(content, is_server) {
|
|
|
484
489
|
if (node.jsDoc) {
|
|
485
490
|
// @ts-ignore
|
|
486
491
|
for (const comment of node.jsDoc) {
|
|
487
|
-
for (const tag of comment.tags) {
|
|
492
|
+
for (const tag of comment.tags ?? []) {
|
|
488
493
|
if (ts.isJSDocTypeTag(tag)) {
|
|
489
494
|
const is_fn =
|
|
490
495
|
ts.isFunctionDeclaration(value) ||
|
package/types/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface Adapter {
|
|
|
25
25
|
adapt(builder: Builder): MaybePromise<void>;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
type AwaitedPropertiesUnion<input extends Record<string, any> | void> = input extends void
|
|
29
29
|
? undefined // needs to be undefined, because void will break intellisense
|
|
30
30
|
: input extends Record<string, any>
|
|
31
31
|
? {
|
|
@@ -35,10 +35,22 @@ export type AwaitedProperties<input extends Record<string, any> | void> = input
|
|
|
35
35
|
? input
|
|
36
36
|
: unknown;
|
|
37
37
|
|
|
38
|
+
export type AwaitedProperties<input extends Record<string, any> | void> =
|
|
39
|
+
AwaitedPropertiesUnion<input> extends Record<string, any>
|
|
40
|
+
? OptionalUnion<AwaitedPropertiesUnion<input>>
|
|
41
|
+
: AwaitedPropertiesUnion<input>;
|
|
42
|
+
|
|
38
43
|
export type AwaitedActions<T extends Record<string, (...args: any) => any>> = {
|
|
39
|
-
[Key in keyof T]: UnpackValidationError<Awaited<ReturnType<T[Key]
|
|
44
|
+
[Key in keyof T]: OptionalUnion<UnpackValidationError<Awaited<ReturnType<T[Key]>>>>;
|
|
40
45
|
}[keyof T];
|
|
41
46
|
|
|
47
|
+
// Takes a union type and returns a union type where each type also has all properties
|
|
48
|
+
// of all possible types (typed as undefined), making accessing them more ergonomic
|
|
49
|
+
type OptionalUnion<
|
|
50
|
+
U extends Record<string, any>, // not unknown, else interfaces don't satisfy this constraint
|
|
51
|
+
A extends keyof U = U extends U ? keyof U : never
|
|
52
|
+
> = U extends unknown ? { [P in Exclude<A, keyof U>]?: never } & U : never;
|
|
53
|
+
|
|
42
54
|
// Needs to be here, else ActionData will be resolved to unknown - probably because of "d.ts file imports .js file" in combination with allowJs
|
|
43
55
|
interface ValidationError<T extends Record<string, unknown> | undefined = undefined> {
|
|
44
56
|
status: number;
|
|
@@ -128,7 +140,7 @@ export interface Cookies {
|
|
|
128
140
|
/**
|
|
129
141
|
* Gets a cookie that was previously set with `cookies.set`, or from the request headers.
|
|
130
142
|
*/
|
|
131
|
-
get(name: string, opts?: import('cookie').CookieParseOptions): string |
|
|
143
|
+
get(name: string, opts?: import('cookie').CookieParseOptions): string | undefined;
|
|
132
144
|
|
|
133
145
|
/**
|
|
134
146
|
* Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` during the current request.
|