Skip to content

Enable noImplicitAny Typescript compiler flag #1862

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

Merged
merged 17 commits into from
Jun 17, 2019
Merged

Enable noImplicitAny Typescript compiler flag #1862

merged 17 commits into from
Jun 17, 2019

Conversation

hsubox76
Copy link
Contributor

Enabled noImplicitAny Typescript compiler flag on all packages with an exception for database, which would require extensive updates out of scope for this PR.

Copy link
Member

@yuchenshi yuchenshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval for packages/testing

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small question regarding the underscore used in imports, but other Storage LGTM.

import {
FirebaseServiceFactory,
_FirebaseNamespace
} from '@firebase/app-types/private';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this just be FirebaseNamespace? It's not immediately obvious to me why it needs an underscore, but I am willing to learn :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I guess we have:

import { FirebaseNamespace } from '@firebase/app-types';
import { _FirebaseNamespace } from '@firebase/app-types/private';	

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, the public FirebaseNamespace type doesn't have an INTERNAL property which causes a TS error on line 54.

@@ -163,7 +163,7 @@ export function list(
pageToken?: string | null,
maxResults?: number | null
): RequestInfo<ListResult> {
let urlParams = {};
let urlParams: { [key: string]: any } = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have another PR pending that removes any from Storage. Can you use unknown here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually just saw that there was a UrlParams type so I used that. The only change is I have to explicitly cast maxResults to string if that's okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops I guess it wasn't okay. I changed UrlParams to accept string | number values, that seems like a better idea.

Copy link
Contributor

@mikelehen mikelehen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this! The Firestore changes mostly look good, but I'm not wild about introducing @ts-ignore exceptions into our code, so I've taken a crack at fixing them in #1882.

import { XMLHttpRequest } from 'xmlhttprequest';
// Node specific packages.
// eslint-disable-next-line @typescript-eslint/no-require-imports
const Storage = require('dom-storage');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the motivation behind the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dom-storage and xmlhttprequest don't have types so the type of Storage and XMLHttpRequest is implicitly any. Maybe it would be simpler to just @ts-ignore and explain it is a node package.

@@ -80,6 +80,7 @@ export function createFirebaseNamespaceCore(
//
// import * as firebase from 'firebase';
// which becomes: var firebase = require('firebase');
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, please cast to any and use eslint suppression instead of @ts-ignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

function mapValues(o: object, f: (any) => any): object {
let result = {};
function mapValues(o: { [key: string]: any }, f: (arg0: any) => any): object {
let result: { [key: string]: any } = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use unknown instead. No action is needed . Explicit any is being tackled in eslint PRs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

try {
sizeString = xhr.getResponseHeader('X-Goog-Upload-Size-Received');
if (sizeString === null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is not needed. parseInt will produce NaN which will be caught by isNaN check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -212,7 +212,8 @@ export function loadFirestoreRules(
project: `projects/${options.projectId}`,
rules: { files: [{ content: options.rules }] }
},
(err, resp) => {
// @ts-ignore Defined in protobuf.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use unknown type here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve() won't accept unknown

@@ -18,26 +18,34 @@
import { base64Decode } from './crypt';
import { jsonEval } from './json';

interface Claims {
[key: string]: object | number | string | boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use {} as type ? {} also includes symbol, but it should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if (typeof claims === 'object' && claims.hasOwnProperty('iat')) {
return claims['iat'];
return claims['iat'] as number | null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it just be number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -18,12 +18,20 @@
/* eslint-disable */
// will enable after https://github.com/firebase/firebase-js-sdk/pull/1811 is merged

interface UtilObject<V> {
[key: string]: V;
[index: number]: V;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to define a number index. All number indexing are string indexing under the hood.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, I was previously getting a lot of errors in places that used this functions with number-indexed objects but I guess those errors got fixed on the consuming end. Done.

* Fix packages/firestore/ usages of @ts-ignore.

I left the equality_matcher.ts ones for the code we copy/pasted in, but fixed the rest.
Copy link
Contributor

@mikelehen mikelehen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for Firestore.

@hsubox76 hsubox76 merged commit 7866e22 into master Jun 17, 2019
@hsubox76 hsubox76 deleted the ch-strict branch June 17, 2019 23:02
@firebase firebase locked and limited conversation to collaborators Oct 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants