Skip to content

Make event params strongly typed #1155

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 12 commits into from
Aug 22, 2022
Merged

Make event params strongly typed #1155

merged 12 commits into from
Aug 22, 2022

Conversation

inlined
Copy link
Member

@inlined inlined commented Jun 28, 2022

Implements go/cf3-typed-params.

WIP: currently only common and v2 are implemented.

Had to update prettier to the next major version so it could read TS 4.1 features without erroring out. I created #1160 as a base for this change to make it easier to separate mechanical from hand-crafted changes. If this is approved, however, I'll commit both changes to launch.next

@inlined inlined requested review from colerogers and taeold June 28, 2022 06:06
@inlined inlined force-pushed the inlined.typed-params branch from 4042731 to 801a7b8 Compare June 29, 2022 21:13
@inlined inlined changed the base branch from launch.next to inlined.update-prettier June 29, 2022 21:18
Base automatically changed from inlined.update-prettier to launch.next July 13, 2022 18:37
@taeold taeold added this to the v4 milestone Aug 22, 2022
Copy link
Contributor

@taeold taeold left a comment

Choose a reason for hiding this comment

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

Coolest PR of the year

Comment on lines 78 to 84
it('falls back to Record<string, string> without better type info', () => {
expectType<ParamsOf<string>>({} as Record<string, string>);
});

it('is the empty object when there are no params', () => {
expectType<ParamsOf<string>>({} as Record<string, never>);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

q: How does these two test case (which look identical to me) both pass 🤔 ?

ParamsOf<string> is both Record<string, string> and Record<string, never>?

@taeold taeold merged commit 87ca228 into launch.next Aug 22, 2022
@taeold taeold mentioned this pull request Aug 23, 2022
taeold added a commit that referenced this pull request Aug 23, 2022
Integration test caught some bugs!

1. From #1155 - Some internal type must be exposed - otherwise compiling user projects fails w/ error message like below:

```
Error: node_modules/firebase-functions/lib/common/params.d.ts(10,13): error TS2314: Generic type 'Extract' requires 2 type argument(s).
Error: node_modules/firebase-functions/lib/common/params.d.ts(10,21): error TS2304: Cannot find name 'Split'.
Error: node_modules/firebase-functions/lib/common/params.d.ts(10,27): error TS2304: Cannot find name 'NullSafe'.
```

2. From #1181 - There is no way to call private callable functions since GCF requrie GCP identity token as authorization header while callable function requires Firebase auth tokens. Disabling those test cases in the integration test until we can mint a GCP project w/ permission to create public functions.
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.

3 participants