人只有在人们中间才能认识自己。——歌德

题目:

1
2
3
4
declare module 'str-utils' {
// export const ...
// export function ...
}

报错:

1
2
3
4
5
6
index.ts(2,5): error TS2305: Module '"str-utils"' has no exported member 'strReverse'.
index.ts(3,5): error TS2305: Module '"str-utils"' has no exported member 'strToLower'.
index.ts(4,5): error TS2305: Module '"str-utils"' has no exported member 'strToUpper'.
index.ts(5,5): error TS2305: Module '"str-utils"' has no exported member 'strRandomize'.
index.ts(6,5): error TS2305: Module '"str-utils"' has no exported member 'strInvertCase'.
test.ts(5,5): error TS2344: Type 'false' does not satisfy the constraint 'true'.

答案:

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
declare module 'str-utils' {

/**
* Reverses a string.
* @param {String} value
* @return {String}
*/
export function strReverse(value: string): string

/**
* Converts a string to lower case.
* @param {String} value
* @return {String}
*/
export function strToLower(value: string): string

/**
* Converts a string to upper case.
* @param {String} value
* @return {String}
*/
export function strToUpper(value: string): string

/**
* Randomizes characters of a string.
* @param {String} value
* @return {String}
*/
export function strRandomize(value: string): string

/**
* Inverts case of a string.
* @param {String} value
* @return {String}
*/
export function strInvertCase(value: string) :string

}