Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Adjust color type to make it more safe #746

Open
@jfrolich

Description

@jfrolich

The problem

Now that we havePlatformColor (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 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.

Considered solution

So to make colors safe I think we should make them phantom typed.

type t<'a>external string: string => t<string> = "%identity"external get: color<'a> => 'a = "%identity"...let blue = Color.string("blue")let blueString = Color.get(blue)

With platform colors beingcolor<PlatformColor.t>.

InStyle.t we can accept all colors (we need a lot of type parameters in the external though)

Alternative solution

An opaque type. The type of the color would be lost, so we can't easily have aget ortoString that would raise a type error for a platform color. The upside for this is that we need less type parameters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp