Skip to content
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

shareTarget derives full action URL #391

Merged
merged 2 commits into from
Nov 6, 2020

Conversation

andreban
Copy link
Member

@andreban andreban commented Nov 6, 2020

  • Derive the full action URL from the Web Manifest URL.
  • Extracts mime-types from share-target.

Improves #21

@andreban andreban added the enhancement New feature or request label Nov 6, 2020
- Derive the full action URL from the Web Manifest URL.
- Extracts mime-types from share-target.
Copy link
Collaborator

@PEConn PEConn left a comment

Choose a reason for hiding this comment

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

I think this looks good - I'm a little unsure about why we're using undefined instead of null though.

});
return twaManifest;
}

private static verifyShareTarget(
webManifestUrl: URL, shareTarget?: ShareTarget): ShareTarget | undefined {
if (!shareTarget || !shareTarget.action || !shareTarget.params || !shareTarget.params.files) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this not be if (!shareTarget?.action || !shareTarget.params?.files)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. done.

@andreban
Copy link
Member Author

andreban commented Nov 6, 2020

Unfortunately, when a field is defined as optional like shareTarget? : ShareTarget), that means ShareTarget | undefined and returning null causes a compilation error. (Type 'ShareTarget | null' is not assignable to type 'ShareTarget | undefined'.)

Copy link
Collaborator

@PEConn PEConn left a comment

Choose a reason for hiding this comment

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

Looks good with nit.

});
return twaManifest;
}

private static verifyShareTarget(
webManifestUrl: URL, shareTarget?: ShareTarget): ShareTarget | undefined {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The return type can be ShareTarget? right?

Copy link
Member Author

Choose a reason for hiding this comment

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

The optional syntax only works for attributes, variable declarations and parameters. Not for return types.

@PEConn
Copy link
Collaborator

PEConn commented Nov 6, 2020

Oh, it seems I still don't understand TypeScript. LGTM again.

@andreban andreban merged commit 071a56e into GoogleChromeLabs:master Nov 6, 2020
@andreban andreban deleted the share-target-improvement branch November 6, 2020 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants