Skip to content

Commit

Permalink
fix: remove most of @ts-ignores from the generated code (#44)
Browse files Browse the repository at this point in the history
* fix: remove most of @ts-ignores from the generated code

* Update package.json
  • Loading branch information
alexander-fenster committed Oct 11, 2019
1 parent de6a2b0 commit 27dfea2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion templates/typescript_gapic/package.json.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"description": "{{ api.naming.productName }} client for Node.js",
"main": "build/src/index.js",
"dependencies": {
"google-gax": "^1.7.2"
"google-gax": "^1.7.3"
},
"devDependencies": {
"@types/mocha": "^5.2.5",
Expand Down
20 changes: 7 additions & 13 deletions templates/typescript_gapic/src/$version/$service_client.ts.njk
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,14 @@ export class {{ service.name }}Client {

const operationsClient = gaxModule.lro({
auth: this.auth,
// @ts-ignore
grpc: gaxGrpc.grpc,
grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined
}).operationsClient(opts);

{%- for method in service.longRunning %}
const {{ method.name.toCamelCase() }}Response = protoFilesRoot.lookup(
'{{ method.longRunning.responseType }}');
'{{ method.longRunning.responseType }}') as gax.protobuf.Type;
const {{ method.name.toCamelCase() }}Metadata = protoFilesRoot.lookup(
'{{ method.longRunning.metadataType }}');
'{{ method.longRunning.metadataType }}') as gax.protobuf.Type;
{%- endfor %}

this._descriptors.longrunning = {
Expand All @@ -161,9 +160,7 @@ export class {{ service.name }}Client {
{{- longRunningJoiner() }}
{{ method.name.toCamelCase() }}: new gaxModule.LongrunningDescriptor(
operationsClient,
// @ts-ignore
{{ method.name.toCamelCase() }}Response.decode.bind({{ method.name.toCamelCase() }}Response),
// @ts-ignore
{{ method.name.toCamelCase() }}Metadata.decode.bind({{ method.name.toCamelCase() }}Metadata))
{%- endfor %}
};
Expand All @@ -182,13 +179,12 @@ export class {{ service.name }}Client {
// Put together the "service stub" for
// google.showcase.v1alpha2.Echo.
const {{ service.name.toCamelCase() }}Stub = gaxGrpc.createStub(
// @ts-ignore We cannot check types that are loaded in runtime.
opts.fallback ?
// @ts-ignore
// @ts-ignore Do not check types for loaded protos
protos.lookupService('{{api.naming.protoPackage}}.{{ service.name }}') :
// @ts-ignore
// @ts-ignore Do not check types for loaded protos
protos.{{api.naming.protoPackage}}.{{ service.name }},
opts);
opts) as Promise<{[method: string]: Function}>;

const {{ service.name.toCamelCase() }}StubMethods =
[
Expand All @@ -200,10 +196,8 @@ export class {{ service.name }}Client {
];

for (const methodName of {{ service.name.toCamelCase() }}StubMethods) {
// @ts-ignore
const innerCallPromise = {{ service.name.toCamelCase() }}Stub.then(
// @ts-ignore
stub => (...args: Array<{}>) => {
(stub: {[method: string]: Function}) => (...args: Array<{}>) => {
return stub[methodName].apply(stub, args);
},
(err: Error|null|undefined) => () => {
Expand Down
5 changes: 4 additions & 1 deletion templates/typescript_gapic/tslint.json.njk
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "gts/tslint.json"
"extends": "gts/tslint.json",
"rules": {
"ban-ts-ignore": false
}
}
2 changes: 2 additions & 0 deletions typescript/test/test_application_js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
},
"dependencies": {
"showcase": "file:./showcase-0.1.0.tgz",
"@grpc/grpc-js": "^0.6.8",
"grpc": "^1.23.3",
"is-docker": "^2.0.0",
"karma": "^4.3.0",
"karma-chrome-launcher": "^3.1.0",
Expand Down
20 changes: 7 additions & 13 deletions typescript/test/testdata/echo_client_baseline.ts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,17 @@ export class EchoClient {

const operationsClient = gaxModule.lro({
auth: this.auth,
// @ts-ignore
grpc: gaxGrpc.grpc,
grpc: 'grpc' in gaxGrpc ? gaxGrpc.grpc : undefined
}).operationsClient(opts);
const waitResponse = protoFilesRoot.lookup(
'WaitResponse');
'WaitResponse') as gax.protobuf.Type;
const waitMetadata = protoFilesRoot.lookup(
'WaitMetadata');
'WaitMetadata') as gax.protobuf.Type;

this._descriptors.longrunning = {
wait: new gaxModule.LongrunningDescriptor(
operationsClient,
// @ts-ignore
waitResponse.decode.bind(waitResponse),
// @ts-ignore
waitMetadata.decode.bind(waitMetadata))
};

Expand All @@ -178,22 +175,19 @@ export class EchoClient {
// Put together the "service stub" for
// google.showcase.v1alpha2.Echo.
const echoStub = gaxGrpc.createStub(
// @ts-ignore We cannot check types that are loaded in runtime.
opts.fallback ?
// @ts-ignore
// @ts-ignore Do not check types for loaded protos
protos.lookupService('google.showcase.v1beta1.Echo') :
// @ts-ignore
// @ts-ignore Do not check types for loaded protos
protos.google.showcase.v1beta1.Echo,
opts);
opts) as Promise<{[method: string]: Function}>;

const echoStubMethods =
['echo', 'expand', 'collect', 'chat', 'pagedExpand', 'wait'];

for (const methodName of echoStubMethods) {
// @ts-ignore
const innerCallPromise = echoStub.then(
// @ts-ignore
stub => (...args: Array<{}>) => {
(stub: {[method: string]: Function}) => (...args: Array<{}>) => {
return stub[methodName].apply(stub, args);
},
(err: Error|null|undefined) => () => {
Expand Down

0 comments on commit 27dfea2

Please sign in to comment.