-
Notifications
You must be signed in to change notification settings - Fork 943
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain to me what the bang here means? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 I can fix it by adding an else at the end that assigns There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :) |
||
private size_: number; | ||
private type_: string; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,8 +63,11 @@ export class Service { | |
* bucket. | ||
*/ | ||
ref(path?: string): Reference { | ||
function validator(path: string): void { | ||
if (/^[A-Za-z]+:\/\//.test(path)) { | ||
function validator(path: unknown): void { | ||
if (typeof path !== 'string') { | ||
throw 'Path is not a string.'; | ||
} | ||
if (/^[A-Za-z]+:\/\//.test(path as string)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will give it a shot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you do the same thing for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
throw 'Expected child path but got a URL, use refFromURL instead.'; | ||
} | ||
} | ||
|
@@ -86,12 +89,15 @@ export class Service { | |
* which must be a gs:// or http[s]:// URL. | ||
*/ | ||
refFromURL(url: string): Reference { | ||
function validator(p: string): void { | ||
if (!/^[A-Za-z]+:\/\//.test(p)) { | ||
function validator(p: unknown): void { | ||
if (typeof p !== 'string') { | ||
throw 'Path is not a string.'; | ||
} | ||
if (!/^[A-Za-z]+:\/\//.test(p as string)) { | ||
throw 'Expected full URL but got a child path, use ref instead.'; | ||
} | ||
try { | ||
Location.makeFromUrl(p); | ||
Location.makeFromUrl(p as string); | ||
} catch (e) { | ||
throw 'Expected valid full URL but got an invalid one.'; | ||
} | ||
|
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.