@@ -68,30 +68,53 @@ export const differential_headers_assignment: RequestHandler = () => {
68
68
}
69
69
} ;
70
70
71
- // TODO https://github.com/sveltejs/kit/issues/1997
72
- // interface ExamplePost {
73
- // title: string;
74
- // description: string;
75
- // published_date?: string;
76
- // author_name?: string;
77
- // author_link?: string;
78
- // }
79
- // // valid - should not be any different
80
- // export const generic_case: RequestHandler<Record<string, string>, ExamplePost> = () => {
81
- // return {
82
- // body: {} as ExamplePost
83
- // };
84
- // };
71
+ /**
72
+ * NOTE about type casting in body returned
73
+ *
74
+ * tests below with `{} as Interface` casts are there only for
75
+ * convenience purposes so we won't have to actually fill in the
76
+ * required data, it serves the exact same purpose and doesn't
77
+ * make the tests invalid
78
+ */
79
+
80
+ /** example json-serializable POJO */
81
+ interface ExamplePost {
82
+ title : string ;
83
+ description : string ;
84
+ published_date ?: string ;
85
+ author_name ?: string ;
86
+ author_link ?: string ;
87
+ }
88
+ // valid - should not be any different
89
+ export const generic_case : RequestHandler < Record < string , string > , ExamplePost > = ( ) => {
90
+ return {
91
+ body : { } as ExamplePost
92
+ } ;
93
+ } ;
85
94
86
95
// --- invalid cases ---
87
96
88
97
// @ts -expect-error - body must be JSON serializable
89
- export const error_body_must_be_serializable : RequestHandler = ( ) => {
98
+ export const error_unserializable_literal : RequestHandler = ( ) => {
90
99
return {
91
100
body : ( ) => { }
92
101
} ;
93
102
} ;
94
103
104
+ /** example object that isn't serializable */
105
+ interface InvalidPost {
106
+ sorter ( a : any , b : any ) : number ;
107
+ }
108
+ // @ts -expect-error - body must be JSON serializable with Generic passed
109
+ export const error_unserializable_generic : RequestHandler <
110
+ Record < string , string > ,
111
+ InvalidPost
112
+ > = ( ) => {
113
+ return {
114
+ body : { } as InvalidPost
115
+ } ;
116
+ } ;
117
+
95
118
// @ts -expect-error - body typed array must only be Uint8Array
96
119
export const error_other_typed_array_instances : RequestHandler = ( ) => {
97
120
return {
0 commit comments