Referencing built-in types by module / namespace
What I won't do is pretty much:
type alias String = { prop: String -- here I want a native String }
It won't work as the compiler naturally assumes it is recursive. I assumed some module would call its own type, but neither Basics.String
nor String.String
does it work.
So, is there a way for your own types to use the same name as their native type and still reference their own?
+3
source to share
1 answer
I'm not sure if this is a great idea, in terms of readability, but to address the question of whether it is possible, it will work if you create an alias for String
in another module.
Something like this will work:
Alias.elm
module Alias exposing (..)
type alias ElmString =
String
Main.elm
module Main exposing (..)
import Alias exposing (ElmString)
type alias String =
{ prop: ElmString
}
+4
source to share