Skip to content

Commit cdf5a53

Browse files
author
Elad Ben-Israel
authored
fix(jsii): do not mark "any" or "unknown" as optional (unless "?") (#295)
We accidentally marked every "any" and "unknown" types as optional, regardless if the declaration had a question mark or not. Fixes #284
1 parent b7b91db commit cdf5a53

File tree

21 files changed

+262
-92
lines changed

21 files changed

+262
-92
lines changed

packages/jsii-calc-base/test/assembly.jsii

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
},
7474
"name": "typeName",
7575
"returns": {
76-
"optional": true,
7776
"primitive": "any"
7877
}
7978
}
@@ -103,5 +102,5 @@
103102
}
104103
},
105104
"version": "0.7.8",
106-
"fingerprint": "K1rAUs6WiQ5lF08T46B8v/5UL8T8Ot59e0Nc8rh2jiQ="
105+
"fingerprint": "FbKHAP60R40tOOnvhCeDrZDrNlgzIypOfAdWPed+Jog="
107106
}

packages/jsii-calc/lib/compliance.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,3 +939,12 @@ export interface IInterfaceWithMethods {
939939
export interface IInterfaceThatShouldNotBeADataType extends IInterfaceWithMethods {
940940
readonly otherValue: string;
941941
}
942+
943+
/**
944+
* jsii#284: do not recognize "any" as an optional argument
945+
*/
946+
export class DoNotRecognizeAnyAsOptional {
947+
public method(_requiredAny: any, _optionalAny?: any, _optionalString?: string) {
948+
949+
}
950+
}

packages/jsii-calc/test/assembly.jsii

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@
382382
"type": {
383383
"collection": {
384384
"elementtype": {
385-
"optional": true,
386385
"primitive": "any"
387386
},
388387
"kind": "array"
@@ -394,13 +393,18 @@
394393
"type": {
395394
"collection": {
396395
"elementtype": {
397-
"optional": true,
398396
"primitive": "any"
399397
},
400398
"kind": "map"
401399
}
402400
}
403401
},
402+
{
403+
"name": "anyProperty",
404+
"type": {
405+
"primitive": "any"
406+
}
407+
},
404408
{
405409
"name": "arrayProperty",
406410
"type": {
@@ -528,7 +532,6 @@
528532
"type": {
529533
"collection": {
530534
"elementtype": {
531-
"optional": true,
532535
"primitive": "any"
533536
},
534537
"kind": "array"
@@ -540,17 +543,15 @@
540543
"type": {
541544
"collection": {
542545
"elementtype": {
543-
"optional": true,
544546
"primitive": "any"
545547
},
546548
"kind": "map"
547549
}
548550
}
549551
},
550552
{
551-
"name": "anyProperty",
553+
"name": "unknownProperty",
552554
"type": {
553-
"optional": true,
554555
"primitive": "any"
555556
}
556557
},
@@ -560,13 +561,6 @@
560561
"fqn": "jsii-calc.StringEnum",
561562
"optional": true
562563
}
563-
},
564-
{
565-
"name": "unknownProperty",
566-
"type": {
567-
"optional": true,
568-
"primitive": "any"
569-
}
570564
}
571565
]
572566
},
@@ -1301,6 +1295,45 @@
13011295
],
13021296
"name": "DoNotOverridePrivates"
13031297
},
1298+
"jsii-calc.DoNotRecognizeAnyAsOptional": {
1299+
"assembly": "jsii-calc",
1300+
"docs": {
1301+
"comment": "jsii#284: do not recognize \"any\" as an optional argument"
1302+
},
1303+
"fqn": "jsii-calc.DoNotRecognizeAnyAsOptional",
1304+
"initializer": {
1305+
"initializer": true
1306+
},
1307+
"kind": "class",
1308+
"methods": [
1309+
{
1310+
"name": "method",
1311+
"parameters": [
1312+
{
1313+
"name": "_requiredAny",
1314+
"type": {
1315+
"primitive": "any"
1316+
}
1317+
},
1318+
{
1319+
"name": "_optionalAny",
1320+
"type": {
1321+
"optional": true,
1322+
"primitive": "any"
1323+
}
1324+
},
1325+
{
1326+
"name": "_optionalString",
1327+
"type": {
1328+
"optional": true,
1329+
"primitive": "string"
1330+
}
1331+
}
1332+
]
1333+
}
1334+
],
1335+
"name": "DoNotRecognizeAnyAsOptional"
1336+
},
13041337
"jsii-calc.DoubleTrouble": {
13051338
"assembly": "jsii-calc",
13061339
"fqn": "jsii-calc.DoubleTrouble",
@@ -3062,7 +3095,6 @@
30623095
{
30633096
"name": "value",
30643097
"returns": {
3065-
"optional": true,
30663098
"primitive": "any"
30673099
}
30683100
}
@@ -3412,5 +3444,5 @@
34123444
}
34133445
},
34143446
"version": "0.7.8",
3415-
"fingerprint": "Xn7Rk17rqR3AaMx3+ssxT0GR1sCWwz0OGC+C8QuLI3A="
3447+
"fingerprint": "2BaszImarh4WChl9DFUcygfTpEfXU17fHQT2wgEptfM="
34163448
}

packages/jsii-java-runtime-test/project/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
bin/
2+
13
!index.js
24
.idea
35
pom.xml

packages/jsii-java-runtime/project/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
bin/
2+
13
!index.js
24
.idea
35
pom.xml

packages/jsii-pacmak/test/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
**/java/bin/
2+
13
!*.tgz
24

packages/jsii-pacmak/test/expected.jsii-calc-base/dotnet/Amazon.JSII.Tests.CalculatorPackageId.BasePackageId/.jsii

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
},
7474
"name": "typeName",
7575
"returns": {
76-
"optional": true,
7776
"primitive": "any"
7877
}
7978
}
@@ -103,5 +102,5 @@
103102
}
104103
},
105104
"version": "0.7.8",
106-
"fingerprint": "K1rAUs6WiQ5lF08T46B8v/5UL8T8Ot59e0Nc8rh2jiQ="
105+
"fingerprint": "FbKHAP60R40tOOnvhCeDrZDrNlgzIypOfAdWPed+Jog="
107106
}

packages/jsii-pacmak/test/expected.jsii-calc-base/dotnet/Amazon.JSII.Tests.CalculatorPackageId.BasePackageId/Amazon/JSII/Tests/CalculatorNamespace/BaseNamespace/Base.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected Base(DeputyProps props): base(props)
1919
}
2020

2121
/// <returns>the name of the class (to verify native type names are created for derived classes).</returns>
22-
[JsiiMethod("typeName", "{\"primitive\":\"any\",\"optional\":true}", "[]")]
22+
[JsiiMethod("typeName", "{\"primitive\":\"any\"}", "[]")]
2323
public virtual object TypeName()
2424
{
2525
return InvokeInstanceMethod<object>(new object[]{});

packages/jsii-pacmak/test/expected.jsii-calc-base/java/src/main/java/software/amazon/jsii/tests/calculator/base/Base.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ protected Base(final software.amazon.jsii.JsiiObject.InitializationMode mode) {
1313
/**
1414
* @return the name of the class (to verify native type names are created for derived classes).
1515
*/
16-
@javax.annotation.Nullable
1716
public java.lang.Object typeName() {
1817
return this.jsiiCall("typeName", java.lang.Object.class);
1918
}

packages/jsii-pacmak/test/expected.jsii-calc-base/sphinx/_scope_jsii-calc-base.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Base
158158
.. py:method:: typeName() -> any
159159
160160
:return: the name of the class (to verify native type names are created for derived classes).
161-
:rtype: any or ``undefined``
161+
:rtype: any
162162

163163

164164
BaseProps (interface)

0 commit comments

Comments
 (0)