Skip to content

Conversation

@samtstern
Copy link
Contributor

Right now it's easy to write snippets in this repo which won't actually work, which somewhat defeats the point.

We can use TypeScript to get much better checking on our JS snippets because many of our deps (like firebase-admin) ship with types.

This helped me find a bunch of useful errors in the auth module, although I am stuck on a few.

Valid remaining errors (our stuff is actually broken):

manage_users.js(46,14): error TS2551: Property 'getUsers' does not exist on type 'Auth'. Did you mean 'getUser'?
manage_users.js(132,14): error TS2551: Property 'deleteUsers' does not exist on type 'Auth'. Did you mean 'deleteUser'?

Invalid remaining errors (I need help with these):

custom_claims.js(31,39): error TS2339: Property 'admin' does not exist on type 'Object'.
custom_claims.js(55,27): error TS2339: Property 'admin' does not exist on type 'Object'.
get_service_account_tokens.js(20,32): error TS2732: Cannot find module 'path/to/serviceAccountKey.json'. Consider using '--resolveJsonModule' to import module with '.json' extension

@samtstern
Copy link
Contributor Author

@abeisgoat @jhuleatt @jamesdaniels would love to know your thoughts on this method.

@jhuleatt
Copy link
Collaborator

One way to resolve TS errors is to annotate types with comments in the JS files. Might help with the Property 'admin' does not exist on type 'Object' warnings

@samtstern
Copy link
Contributor Author

@jhuleatt you're OOO get outta here! But thank you.

@samtstern
Copy link
Contributor Author

This now fails for the right reasons: auth contains snippets for an unreleased SDK (bulk user fetch/delete)

@samtstern samtstern merged commit 468dc88 into master Mar 31, 2020
admin.auth().getUser(uid).then((userRecord) => {
// The claims can be accessed on the user record.
console.log(userRecord.customClaims.admin);
console.log(userRecord.customClaims['admin']);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this switched from customClaims.admin to customClaims['admin'] here and below to make the compiler happy? I think the original .admin syntax is nicer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it was ... do you have a suggestion for how we can have the . syntax? I actually don't mind this because it shows a division between types parts userRecord.customClaims and the any Danger Zone

@morganchen12 morganchen12 deleted the ss-type-checking branch November 6, 2025 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants