-
Notifications
You must be signed in to change notification settings - Fork 26
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
Example doesn't seem to work #24
Comments
Oh, after some recent changes you need to include the type parameter. So |
Thanks. I noticed that this is the intended usage from the tests, but I was unsure since I didn't manage to get it working in my code (not the one mentioned above).
Is this possible? |
Yes, it's possible as long as when you call Somewhat related to this, there is special built-in support for type families, when get mapped to TypeScript lookup types. You can also see that in the |
Could you write an simple example of what to pass to my |
data X f = X (f Int)
$(deriveTypeScript A.defaultOptions ''X)
-- Unfortunately we need to declare this funny instance because the constraints on
-- getTypeScriptDeclarations are a little too tight in this case
instance TypeScript (HashMap String) where
getTypeScriptType _ = "void"
decls = getTypeScriptDeclarations (Proxy :: Proxy (X (HashMap String)))
|
So is this something like making and typescript type for a "subtype" Y of X where |
My ultimate goal is to have this type in haskell: |
The part where you want type family MyTypeFamily a = result | result -> a where
MyTypeFamily Int = String
MyTypeFamily String = Bool
MyTypeFamily T = Int
data X a = X (MyTypeFamily a)
$(deriveTypeScript' A.defaultOptions ''X (ExtraTypeScriptOptions { typeFamiliesToMapToTypeScript = [''MyTypeFamily] }))
decls = getTypeScriptDeclarationsRecursively (Proxy :: Proxy (X T)) > putStrLn $ formatTSDeclarations decls
interface MyTypeFamily {
number: string;
string: boolean;
T: number;
}
type IX<T extends keyof MyTypeFamily> = MyTypeFamily[T];
type X<T extends keyof MyTypeFamily> = IX<T>; In general, TypeScript has a less powerful type system than Haskell, so it's hard to map your |
I updated the docs so I'm going to close this now, but feel free to let me know if you have any other questions. |
The example with type
D
doesn't seem to work on the type alone (without given type params).Similar behaviour (same error) happens with more simple example from tests:
which results in:
The text was updated successfully, but these errors were encountered: