pprice opened a new pull request #2462:
URL: https://github.com/apache/thrift/pull/2462
Fixes two cases where the optional flag `?` is generated incorrectly for
typescript, leading to invalid typescript generation that cannot pass `tsc`
builds.
### 1. Exception types with optional message
It is possible to set an optional message parameter on thrift exception
types.
```thrift
exception Bad {
1: string message = "";
}
```
However, for the javascript runtime, thrift exception types ultimately
derive from `Error` which has a *required* message field.
**Before**
```ts
export declare class Bad extends Thrift.TException {
message?: string;
}
```
Error: TS2416
```
Property 'message' in type 'T' is not assignable to the same property in
base type 'Error'.
Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.(2416)
```
**After**
```ts
export declare class Bad extends Thrift.TException {
message: string;
}
```
### Non-optional function arguments after optional arguments
For service methods it is possible to have non-optional arguments after
optional arguments, however this is *not* valid in typescript.
```thrift
service Blah {
double getBlah(1: string arg1, 2: string arg2 = "foo", 3: string arg3);
// ~~~~~~~~~~~~~~~~
}
```
**Before**
```ts
export declare class BlahClient {
getBlah(arg1: string, arg2?: string, arg3: string): Promise<number>;
// ~~~~~~~~~~~~~~~~
}
```
Error: TS1016
```
A required parameter cannot follow an optional parameter.
```
**After**
```ts
export declare class BlahClient {
getBlah(arg1: string, arg2?: string, arg3?: string): Promise<number>;
// ~~~~~~~~~~~~~~
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]