forked from TypeStrong/typedoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
function.ts
305 lines (281 loc) · 7.8 KB
/
function.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/**
* This is a simple exported function.
*/
export function exportedFunction(): void {}
/**
* This is a function with multiple arguments and a return value.
*
* @param paramZ - This is a string parameter.
* @param paramG - This is a parameter flagged with any.
* This sentence is placed in the next line.
*
* @param paramA
* This is a **parameter** pointing to an interface.
*
* ~~~
* const value:BaseClass = new BaseClass('test');
* functionWithArguments('arg', 0, value);
* ~~~
*
* @returns This is the return value of the function.
*/
export function functionWithParameters(
paramZ: string,
paramG: any,
paramA: Object
): number {
return 0;
}
/**
* This is a function that is assigned to a variable.
*
* @param someParam This is some numeric parameter.
* @return This is the return value of the function.
*/
export const variableFunction = function (someParam: number): number {
return 0;
};
/**
* This is a function with a parameter that is optional.
*
* @param requiredParam A normal parameter.
* @param optionalParam An optional parameter.
*/
export function functionWithOptionalValue(
requiredParam: string,
optionalParam?: string
) {}
/**
* This is a function with a parameter that has a default value.
*
* @param valueA A parameter with a default string value.
* @param valueB A parameter with a default numeric value.
* @param valueC A parameter with a default NaN value.
* @param valueD A parameter with a default boolean value.
* @param valueE A parameter with a default null value.
* @return This is the return value of the function.
*/
export function functionWithDefaults(
valueA: string = "defaultValue",
valueB: number = 100,
valueC: number = Number.NaN,
valueD: boolean = true,
valueE: boolean = null!
): string {
return valueA;
}
/**
* This is a function with rest parameter.
*
* @param rest The rest parameter.
* @return This is the return value of the function.
*/
export function functionWithRest(...rest: string[]): string {
return rest.join(", ");
}
/**
* This is a function with a destructured parameter.
*
* @param destructuredParam - This is the parameter that is destructured.
* @param destructuredParam.paramZ - This is a string parameter.
* @param destructuredParam.paramG - This is a parameter flagged with any.
* This sentence is placed in the next line.
*
* @param destructuredParam.paramA
* This is a **parameter** pointing to an interface.
*
* ~~~
* const value:BaseClass = new BaseClass('test');
* functionWithArguments('arg', 0, value);
* ~~~
*
* @returns This is the return value of the function.
*/
export function functionWithADestructuredParameter({
paramZ,
paramG,
paramA,
}: {
paramZ: string;
paramG: any;
paramA: Object;
}): number {
return 0;
}
/**
* This is a function with a destructured parameter and additional undocumented parameters.
* The `@param` directives are ignored because we cannot be certain which parameter they refer to.
*
* @param destructuredParam - This is the parameter that is destructured.
* @param destructuredParam.paramZ - This is a string parameter.
* @param destructuredParam.paramG - This is a parameter flagged with any.
* This sentence is placed in the next line.
*
* @param destructuredParam.paramA
* This is a **parameter** pointing to an interface.
*
* ~~~
* const value:BaseClass = new BaseClass('test');
* functionWithArguments('arg', 0, value);
* ~~~
*
* @returns This is the return value of the function.
*/
export function functionWithADestructuredParameterAndExtraParameters(
{
paramZ,
paramG,
paramA,
}: {
paramZ: string;
paramG: any;
paramA: Object;
},
extraParameter: string
): number {
return 0;
}
/**
* This is a function with a destructured parameter and an extra `@param` directive with no corresponding parameter.
* The `@param` directives are ignored because we cannot be certain which corresponds to the real parameter.
*
* @param fakeParameter - This directive does not have a corresponding parameter.
* @param destructuredParam - This is the parameter that is destructured.
* @param destructuredParam.paramZ - This is a string parameter.
* @param destructuredParam.paramG - This is a parameter flagged with any.
* This sentence is placed in the next line.
*
* @param destructuredParam.paramA
* This is a **parameter** pointing to an interface.
*
* ~~~
* const value:BaseClass = new BaseClass('test');
* functionWithArguments('arg', 0, value);
* ~~~
*
* @returns This is the return value of the function.
*/
export function functionWithADestructuredParameterAndAnExtraParamDirective({
paramZ,
paramG,
paramA,
}: {
paramZ: string;
paramG: any;
paramA: Object;
}): number {
return 0;
}
/**
* This is the first signature of a function with multiple signatures.
*
* @param value The name value.
*/
export function multipleSignatures(value: string): string;
/**
* This is the second signature of a function with multiple signatures.
*
* @param value An object containing the name value.
* @param value.name A value of the object.
*/
export function multipleSignatures(value: { name: string }): string;
/**
* This is the actual implementation, this comment will not be visible
* in the generated documentation. The `@inheritdoc` tag can not be used
* to pull content from this signature into documentation for the real
* signatures.
*
* @return This is the return value of the function.
*/
export function multipleSignatures(): string {
if (arguments.length > 0) {
if (typeof arguments[0] === "object") {
return arguments[0].name;
} else {
return arguments[0];
}
}
return "";
}
/**
* This is a function that is extended by a module.
*
* @param arg An argument.
*/
export function moduleFunction(arg: string): string {
return "";
}
/**
* This is an assertion function.
*
* @param condition The condition that is asserted to be true when this function returns.
*/
export function assertionFunction(condition: boolean): asserts condition {}
/**
* Assertion function with a type.
* @param anything
*/
export function checkerFunction(anything: any): anything is string {
return typeof anything === "string";
}
/**
* Asserts that an argument is not null.
* @param arg
*/
export function assertIsNonNull<T>(
arg: T | null | undefined
): asserts arg is T {
if (arg == null) {
throw new Error("Was nullable");
}
}
/**
* Checks that an argument is not null.
* @param arg
*/
export function isNonNull<T>(arg: T | null | undefined): arg is T {
return arg != null;
}
/**
* This is the module extending the function moduleFunction().
*/
export module moduleFunction {
/**
* This variable is appended to a function.
*/
export let functionVariable: string;
/**
* This function is appended to another function.
*/
export function append() {}
/**
* This function is appended to another function.
*/
export function prepend() {}
}
export class Predicates {
static isString(x: unknown): x is string {
return false;
}
isString(): this is string {
return false;
}
static assert(x: unknown): asserts x {}
assertString(): asserts this is string {}
}
/**
* Returns true if fn returns true for every item in the iterator
*
* Returns true if the iterator is empty
*/
export const all: {
<T>(fn: (item: T) => boolean, iterator: Iterable<T>): boolean;
<T>(fn: (item: T) => boolean): (iterator: Iterable<T>) => boolean;
} = () => false as any;
export function boolOrUndef(x: number) {
if (x < 5) return true;
if (x > 20) return false;
return undefined;
}
export function merged() {}
merged.nsFn = function () {};