Skip to content

Commit d0bc904

Browse files
author
John Vilk
committed
Typings now compile in TypeScript!
1 parent acb7b6b commit d0bc904

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

generate/lib/write_ts_declarations.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,44 @@ var writeTsDecls = function(apiData, path) {
2121
return "Array<" + getType(type.slice(0, sqBracketIndex)) + ">";
2222
}
2323

24+
// If type has < in it already, translate generic argument.
25+
var angleIndex = type.indexOf('<');
26+
if (angleIndex !== -1) {
27+
type = type.slice(0, angleIndex) + '<' + getType(type.slice(angleIndex + 1, type.indexOf('>'))) + ">";
28+
}
29+
2430
switch (type) {
31+
// Weird things. Prune items as we fix docs.
32+
case 'obj':
33+
case 'ConvenientHunk':
34+
case 'lineStats':
35+
case 'RevWalk':
36+
case 'StatusFile':
37+
case 'historyEntry':
38+
case 'DiffList':
39+
return 'any';
40+
// Untyped function callbacks.
41+
case 'CheckoutNotifyCb':
42+
case 'CheckoutPerfdataCb':
43+
case 'CheckoutProgressCb':
44+
case 'DiffFileCb':
45+
case 'DiffBinaryCb':
46+
case 'DiffHunkCb':
47+
case 'DiffLineCb':
48+
case 'DiffNotifyCb':
49+
case 'CredAcquireCb':
50+
case 'FetchheadForeachCb':
51+
case 'FilterStreamFn':
52+
case 'IndexMatchedPathCb':
53+
case 'NoteForeachCb':
54+
case 'StashCb':
55+
case 'StashApplyProgressCb':
56+
case 'StatusCb':
57+
case 'SubmoduleCb':
58+
case 'TransferProgressCb':
59+
case 'TransportCb':
60+
case 'TransportCertificateCheckCb':
61+
return 'Function';
2562
// Primitives
2663
case 'String':
2764
return 'string';
@@ -31,6 +68,8 @@ var writeTsDecls = function(apiData, path) {
3168
return 'number';
3269
case 'Void':
3370
return 'void';
71+
case 'bool':
72+
return 'boolean';
3473
case 'Array':
3574
return 'Array<any>';
3675
// Avoiding type collusions
@@ -135,7 +174,7 @@ var writeTsDecls = function(apiData, path) {
135174
var enumFields = " " + Object.keys(enumData).sort().map(function(enumType) {
136175
return enumType + " = " + enumData[enumType];
137176
}).join(",\n ");
138-
return "enum " + exportName + " {\n" + enumFields + "\n}";
177+
return "declare enum " + exportName + " {\n" + enumFields + "\n}";
139178
}
140179

141180
/**
@@ -158,6 +197,7 @@ var writeTsDecls = function(apiData, path) {
158197
// Export specially only if we have to remap the name to avoid type collisions.
159198
if (className !== exportName) {
160199
nameMap[exportName] = className;
200+
classDecl = "declare ";
161201
} else {
162202
classDecl = "export ";
163203
}

0 commit comments

Comments
 (0)