Skip to content

Enable Typescript strict flag for Storage #1935

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 4 commits into from
Jul 8, 2019
Merged

Conversation

hsubox76
Copy link
Contributor

@hsubox76 hsubox76 commented Jul 1, 2019

Enable "strict": true Typescript flag for Storage.

// TODO: This disable can be removed and the 'ignoreRestArgs' option added to
// the no-explicit-any rule when ESlint releases it.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function triggerCallback(...args: any[]): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we follow the same pattern in handler() and change the signature as well? Something like:

function handler(success:boolean, ...args:any[])

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.

@@ -30,7 +30,7 @@ import * as type from './type';
* modified after this blob's construction.
*/
export class FbsBlob {
private data_: Blob | Uint8Array;
private data_!: Blob | Uint8Array;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain to me what the bang here means?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a way of us promising the compiler that this variable will be initialized before anything calls it. The compiler thinks data_ isn't definitively set in the constructor because there's an if and 2 else ifs where it is set, but no else. Since the constructor requires the data param to be of a type that would meet all possible if conditions, it should always get set in the constructor.

I can fix it by adding an else at the end that assigns data_ some default value, which seems risky unless you have a suggestion, or I can just look at the types and promise the compiler data_ is going to get set. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. I have never seen this before. We have a bunch of code in Firestore that we could simplify this way. So keep it as is please :)

mappings.push(new Mapping('generation'));
mappings.push(new Mapping('metageneration'));
mappings.push(new Mapping('name', 'fullPath', true));
const mappings: Array<Mapping<string> | Mapping<number>> = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this not just const mappings: Mappings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right, done.

function validator(path: string): void {
if (/^[A-Za-z]+:\/\//.test(path)) {
function validator(path: unknown): void {
if (/^[A-Za-z]+:\/\//.test(path as string)) {
Copy link
Contributor

@schmidt-sebastian schmidt-sebastian Jul 2, 2019

Choose a reason for hiding this comment

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

If you want to go the extra mile, then I would suggest we also validate explicitly that path is a string. Optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will give it a shot.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you do the same thing for refFromURL below? Thanks!

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.

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.

Thanks!

@hsubox76 hsubox76 merged commit ca8d829 into master Jul 8, 2019
@hsubox76 hsubox76 deleted the ch-strict-storage branch July 8, 2019 17:16
@firebase firebase locked and limited conversation to collaborators Oct 9, 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.

2 participants