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 all commits
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 @@ -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