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

Create a TypeScript type for HTML Strings #6210

Open
rezbyte opened this issue Nov 28, 2023 · 7 comments
Open

Create a TypeScript type for HTML Strings #6210

rezbyte opened this issue Nov 28, 2023 · 7 comments
Labels
idea notes down not immediately solvable things that don't have general buy-in yet maintenance dependency updates, key renewals, code cleanup

Comments

@rezbyte
Copy link
Contributor

rezbyte commented Nov 28, 2023

It would be ideal if we could have a special type for strings that contain HTML code to avoid accidentally passing it to functions that cannot handle it & avoid passing non-HTML strings to functions that expect HTML. For example, the htmlSanitizer or m.trust() if it's possible to override its definition.

@rezbyte rezbyte added maintenance dependency updates, key renewals, code cleanup idea notes down not immediately solvable things that don't have general buy-in yet labels Nov 28, 2023
@charlag
Copy link
Contributor

charlag commented Nov 28, 2023

We could use some kind of branding for it

@rezbyte
Copy link
Contributor Author

rezbyte commented Nov 28, 2023

We could use some kind of branding for it

Would type HTMLString = string not suffice? We still need to find a way to change the parameter type of m.trust() though.

@charlag
Copy link
Contributor

charlag commented Nov 30, 2023

We could use some kind of branding for it

Would type HTMLString = string not suffice? We still need to find a way to change the parameter type of m.trust() though.

no it wouldn't that's just an alias. Like the linked article says, The TypeScript type system is structural.

We usually try to very carefully guard where m.trust is used but inputs to those places could benefit from more strict typing

@rezbyte
Copy link
Contributor Author

rezbyte commented Nov 30, 2023

no it wouldn't that's just an alias. Like the linked article says, The TypeScript type system is structural.

I see. It is strange that TypeScript does not offer a way to strongly type built-in.

We usually try to very carefully guard where m.trust is used but inputs to those places could benefit from more strict typing

It would still be safer to guard types at this low level too however.

@rezbyte
Copy link
Contributor Author

rezbyte commented Nov 30, 2023

FYI built-in support is coming in TypeScript.

@charlag
Copy link
Contributor

charlag commented Nov 30, 2023

Did they promise it or is it just someone's proposal?

@rezbyte
Copy link
Contributor Author

rezbyte commented Nov 30, 2023

It's in their roadmap, so likely yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea notes down not immediately solvable things that don't have general buy-in yet maintenance dependency updates, key renewals, code cleanup
Projects
None yet
Development

No branches or pull requests

2 participants