Skip to content

Commit 571282c

Browse files
Prettier
1 parent e4d6bcf commit 571282c

File tree

3 files changed

+55
-48
lines changed

3 files changed

+55
-48
lines changed

examples/rest-api-client-dts/index.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { RestApiClient } from "./index.js";
55
// @ts-expect-error - An argument for 'options' was not provided
66
let value: typeof RestApiClient = new RestApiClient();
77

8-
expectType<{ userAgent: string; }>(value.defaults);
8+
expectType<{ userAgent: string }>(value.defaults);
99

1010
expectType<{ userAgent: string }>(RestApiClient.defaults);
1111

index.d.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,23 @@ declare type UnionToIntersection<Union> = (
2121
? Intersection
2222
: never;
2323
declare type AnyFunction = (...args: any) => any;
24-
declare type ReturnTypeOf<T extends AnyFunction | AnyFunction[]> =
25-
T extends AnyFunction
26-
? ReturnType<T>
27-
: T extends AnyFunction[]
28-
? UnionToIntersection<Exclude<ReturnType<T[number]>, void>>
29-
: never;
24+
declare type ReturnTypeOf<
25+
T extends AnyFunction | AnyFunction[]
26+
> = T extends AnyFunction
27+
? ReturnType<T>
28+
: T extends AnyFunction[]
29+
? UnionToIntersection<Exclude<ReturnType<T[number]>, void>>
30+
: never;
3031

3132
type ClassWithPlugins = Constructor<any> & {
3233
plugins: Plugin[];
3334
};
3435

35-
type RemainingRequirements<PredefinedOptions> =
36-
keyof PredefinedOptions extends never
37-
? Base.Options
38-
: Omit<Base.Options, keyof PredefinedOptions>;
36+
type RemainingRequirements<
37+
PredefinedOptions
38+
> = keyof PredefinedOptions extends never
39+
? Base.Options
40+
: Omit<Base.Options, keyof PredefinedOptions>;
3941

4042
type NonOptionalKeys<Obj> = {
4143
[K in keyof Obj]: {} extends Pick<Obj, K> ? undefined : K;
@@ -51,10 +53,7 @@ type RequiredIfRemaining<PredefinedOptions, NowProvided> = NonOptionalKeys<
5153
NowProvided
5254
];
5355

54-
type ConstructorRequiringOptionsIfNeeded<
55-
Class,
56-
PredefinedOptions
57-
> = {
56+
type ConstructorRequiringOptionsIfNeeded<Class, PredefinedOptions> = {
5857
defaults: PredefinedOptions;
5958
} & {
6059
new <NowProvided>(
@@ -164,22 +163,22 @@ type Extensions = {
164163

165164
type OrObject<T, Extender> = T extends Extender ? {} : T;
166165

167-
type ApplyPlugins<Plugins extends Plugin[] | undefined> =
168-
Plugins extends Plugin[]
166+
type ApplyPlugins<
167+
Plugins extends Plugin[] | undefined
168+
> = Plugins extends Plugin[]
169169
? UnionToIntersection<ReturnType<Plugins[number]>>
170170
: {};
171171

172172
export type ExtendBaseWith<
173173
BaseClass extends Base,
174174
BaseExtensions extends Extensions
175-
> =
176-
& BaseClass
177-
& ConstructorRequiringOptionsIfNeeded<
178-
BaseClass & ApplyPlugins<BaseExtensions['plugins']>,
179-
OrObject<BaseClass['options'], unknown>
180-
>
181-
& ApplyPlugins<BaseExtensions['plugins']>
182-
& { defaults: OrObject<BaseExtensions['defaults'], undefined> }
183-
;
175+
> = BaseClass &
176+
ConstructorRequiringOptionsIfNeeded<
177+
BaseClass & ApplyPlugins<BaseExtensions["plugins"]>,
178+
OrObject<BaseClass["options"], unknown>
179+
> &
180+
ApplyPlugins<BaseExtensions["plugins"]> & {
181+
defaults: OrObject<BaseExtensions["defaults"], undefined>;
182+
};
184183

185184
export {};

index.test-d.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -229,50 +229,58 @@ expectType<{
229229
defaultThree: string[];
230230
}>({ ...BaseWithManyChainedDefaultsAndPlugins.defaults });
231231

232-
const baseWithManyChainedDefaultsAndPlugins =
233-
new BaseWithManyChainedDefaultsAndPlugins({
232+
const baseWithManyChainedDefaultsAndPlugins = new BaseWithManyChainedDefaultsAndPlugins(
233+
{
234234
required: "1.2.3",
235235
foo: "bar",
236-
});
236+
}
237+
);
237238

238239
expectType<string>(baseWithManyChainedDefaultsAndPlugins.foo);
239240
expectType<string>(baseWithManyChainedDefaultsAndPlugins.bar);
240241
expectType<string>(baseWithManyChainedDefaultsAndPlugins.getFooOption());
241242

242-
declare const RestApiClient: ExtendBaseWith<Base, {
243-
defaults: {
244-
defaultValue: string;
245-
},
246-
plugins: [
247-
() => ({ pluginValueOne: number }),
248-
() => ({ pluginValueTwo: boolean }),
249-
]
250-
}>;
243+
declare const RestApiClient: ExtendBaseWith<
244+
Base,
245+
{
246+
defaults: {
247+
defaultValue: string;
248+
};
249+
plugins: [
250+
() => { pluginValueOne: number },
251+
() => { pluginValueTwo: boolean }
252+
];
253+
}
254+
>;
251255

252256
expectType<string>(RestApiClient.defaults.defaultValue);
253257

254258
// @ts-expect-error
255-
RestApiClient.defaults.unexpected
259+
RestApiClient.defaults.unexpected;
256260

257261
expectType<number>(RestApiClient.pluginValueOne);
258262
expectType<boolean>(RestApiClient.pluginValueTwo);
259263

260264
// @ts-expect-error
261265
RestApiClient.unexpected;
262266

263-
declare const MoreDefaultRestApiClient: ExtendBaseWith<typeof RestApiClient, {
264-
defaults: {
265-
anotherDefaultValue: number;
267+
declare const MoreDefaultRestApiClient: ExtendBaseWith<
268+
typeof RestApiClient,
269+
{
270+
defaults: {
271+
anotherDefaultValue: number;
272+
};
266273
}
267-
}>;
274+
>;
268275

269276
expectType<string>(MoreDefaultRestApiClient.defaults.defaultValue);
270277
expectType<number>(MoreDefaultRestApiClient.defaults.anotherDefaultValue);
271278

272-
declare const MorePluginRestApiClient: ExtendBaseWith<typeof MoreDefaultRestApiClient, {
273-
plugins: [
274-
() => ({ morePluginValue: string[] })
275-
]
276-
}>;
279+
declare const MorePluginRestApiClient: ExtendBaseWith<
280+
typeof MoreDefaultRestApiClient,
281+
{
282+
plugins: [() => { morePluginValue: string[] }];
283+
}
284+
>;
277285

278286
expectType<string[]>(MorePluginRestApiClient.morePluginValue);

0 commit comments

Comments
 (0)