Title: Adjust color type to make it more safe · Issue #746 · rescript-react-native/rescript-react-native · GitHub
Open Graph Title: Adjust color type to make it more safe · Issue #746 · rescript-react-native/rescript-react-native
X Title: Adjust color type to make it more safe · Issue #746 · rescript-react-native/rescript-react-native
Description: The problem Now that we have PlatformColor (nice implementation btw), I think we should think about color not being a type alias to string anymore (part reversal of this PR). I would like to gradually start to use platform colors in my a...
Open Graph Description: The problem Now that we have PlatformColor (nice implementation btw), I think we should think about color not being a type alias to string anymore (part reversal of this PR). I would like to gradua...
X Description: The problem Now that we have PlatformColor (nice implementation btw), I think we should think about color not being a type alias to string anymore (part reversal of this PR). I would like to gradua...
Opengraph URL: https://github.com/rescript-react-native/rescript-react-native/issues/746
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Adjust color type to make it more safe","articleBody":"## The problem\r\n\r\nNow that we have `PlatformColor` (nice implementation btw), I think we should think about color not being a type alias to string anymore [(part reversal of this PR)](https://github.com/rescript-react-native/rescript-react-native/pull/448). I would like to gradually start to use platform colors in my app, now all colors are strings, and sometimes I do some manipulation on them (like darken/lighten), of course that wouldn't work on platform colors.\r\n\r\n## Considered solution\r\n\r\nSo to make colors safe I think we should make them phantom typed.\r\n\r\n```\r\ntype t\u003c'a\u003e\r\nexternal string: string =\u003e t\u003cstring\u003e = \"%identity\"\r\nexternal get: color\u003c'a\u003e =\u003e 'a = \"%identity\"\r\n...\r\nlet blue = Color.string(\"blue\")\r\n\r\nlet blueString = Color.get(blue)\r\n```\r\n\r\nWith platform colors being `color\u003cPlatformColor.t\u003e`.\r\n\r\nIn `Style.t` we can accept all colors (we need a lot of type parameters in the external though)\r\n\r\n## Alternative solution\r\n\r\nAn opaque type. The type of the color would be lost, so we can't easily have a `get` or `toString` that would raise a type error for a platform color. The upside for this is that we need less type parameters.","author":{"url":"https://github.com/jfrolich","@type":"Person","name":"jfrolich"},"datePublished":"2021-06-21T02:57:33.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/746/rescript-react-native/issues/746"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fc487f5b-43b6-5c12-cfc9-dab896745ac1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ADE2:2D90C6:17B5C6E:2101616:69652396 |
| html-safe-nonce | f17b8b99e94fed0f82cd1244f7b8897d9ca28f4a8f0c5884cf189a0fe94d4dd0 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBREUyOjJEOTBDNjoxN0I1QzZFOjIxMDE2MTY6Njk2NTIzOTYiLCJ2aXNpdG9yX2lkIjoiNTMxNDA3MDcxMjQ5MjA0MTExMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fe07d234862cd55f28c392b2255a1549844f30144bc548d54bf015e314b45f15 |
| hovercard-subject-tag | issue:925772302 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/rescript-react-native/rescript-react-native/746/issue_layout |
| twitter:image | https://opengraph.githubassets.com/83daa4a075f477da5b32082d9f0f793830c32451899f9f2a17a6f0b3f616d071/rescript-react-native/rescript-react-native/issues/746 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/83daa4a075f477da5b32082d9f0f793830c32451899f9f2a17a6f0b3f616d071/rescript-react-native/rescript-react-native/issues/746 |
| og:image:alt | The problem Now that we have PlatformColor (nice implementation btw), I think we should think about color not being a type alias to string anymore (part reversal of this PR). I would like to gradua... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jfrolich |
| hostname | github.com |
| expected-hostname | github.com |
| None | 817276b8a3521a687e743b852e21b1c4c62a9fabf649a41d85c1499aaa39fab1 |
| turbo-cache-control | no-preview |
| go-import | github.com/rescript-react-native/rescript-react-native git https://github.com/rescript-react-native/rescript-react-native.git |
| octolytics-dimension-user_id | 54703302 |
| octolytics-dimension-user_login | rescript-react-native |
| octolytics-dimension-repository_id | 86237257 |
| octolytics-dimension-repository_nwo | rescript-react-native/rescript-react-native |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 86237257 |
| octolytics-dimension-repository_network_root_nwo | rescript-react-native/rescript-react-native |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4a4c6d32d56fbcafaf5646e244c8989317f135a9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width