Open nojaf opened 6 years ago
For @types/googlemaps
, you need to pass it the file manually at the same time as react-google-maps
Please note, that ts2fable will generate only strongly typed React components not the DSL used in your view in general which is much more usable from Elmish and F#/Fable POV
Passing @types/googlemaps
indeed works. What about the React stuff?
Given the following TypeScript:
declare module 'react-google-maps/lib/withGoogleMap' {
import { ComponentClass, ReactElement, StatelessComponent } from 'react'
export interface WithGoogleMapProps {
containerElement: ReactElement<any>
mapElement: ReactElement<any>
}
export default function withGoogleMap<P>(wrappedComponent: string | ComponentClass<P> | StatelessComponent<P>): ComponentClass<P & WithGoogleMapProps>
}
Gets translated to
Knowing that ReactElement
looks like
interface ReactElement<P> {
type: string | ComponentClass<P> | SFC<P>;
props: P;
key: Key | null;
}
But the Fable ReactElement interface is not generic.
type ComponentClass = React.ComponentClass
Could be solved by making
type ComponentClass<'a> = React.ComponentClass<'a>
Which makes sense given
interface ComponentClass<P = {}> extends StaticLifecycle<P, any> {
new (props: P, context?: any): Component<P, ComponentState>;
propTypes?: ValidationMap<P>;
contextTypes?: ValidationMap<any>;
childContextTypes?: ValidationMap<any>;
defaultProps?: Partial<P>;
displayName?: string;
}
There is another version of React.fs which is fully generated by ts2fable. I believe you can get more info by comparing these two versions
Hmm everything else in the Fable landscape uses Fable.Import.React bindings. Should these not be fully compatible with the generated React.fs by ts2fable? /cc @alfonsogarciacaro
@nojaf In general, when working with react binding we use the DUs list with keyValueList
style not class style. At least, when targetting Elmish because like that we have a consistant DSL for the views.
Edit: Even if ts2fable is doing a pretty good job, it's not yet ready to parse any d.ts files so for some libraries we don't use it by default yet. At least, it's my POV
I generated the first Fable.Import.React bindings with one of the very first versions of ts2fable and then we did manual tweaking. But yes, it could be a good idea to update it to match the bindings generated with latest ts2fable to make sure we get the updates. We're about to release a new major Fable.React version for Fable 2 so it could be a good opportunity. We will still need some manual tweaking, specially for React.Component
which currently has lots of documentation, some custom members, and default dummy implementations for abstract members users don't necessarily need to implement.
Version: 0.6.1 Steps to reproduce:
Try and generate from
react-google-maps/types/index.d.ts
. For ex:import { Component } from 'react'
should open the React namespace.Changing
React.Component
toFable.Import.React.Component
causesThe type 'Fable.Import.React.Component<_,_>' expects 2 type argument(s) but is given 0
Google.Maps.InfoWindowOptions
,Google
is not known. Should it not parse@types/googlemaps
as well?