Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove most of @ts-ignores from the generated code #44

Merged
merged 3 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -139,15 +139,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 @@ -156,9 +155,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 @@ -177,13 +174,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 @@ -195,10 +191,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
}
}
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 @@ -143,20 +143,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 @@ -173,22 +170,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