ts2fable icon indicating copy to clipboard operation
ts2fable copied to clipboard

Importing dependency is breaking fs file

Open kunjee17 opened this issue 8 years ago • 3 comments

Hi, first of all thanks for wonderful work being done on ts2fable. Things are normally pretty good. But again there are always an edge cases.

Here flatpickr index.d.ts file

import { FlatpickrFn } from "./src/types/instance";
import { Instance as _Instance } from "./src/types/instance";
import {
  Options as _Options,
  Hook as _Hook,
  HookKey as _HookKey,
  ParsedOptions as _ParsedOptions,
  DateLimit as _DateLimit,
  DateOption as _DateOption,
  DateRangeLimit as _DateRangeLimit,
  Plugin as _Plugin,
} from "./src/types/options";

import {
  MonthsWeekDays as _MonthsWeekDays,
  Locale as _Locale,
  CustomLocale as _CustomLocale,
} from "./src/types/locale";

declare var flatpickr: FlatpickrFn;

declare namespace flatpickr {
  export type Instance = _Instance;
  export type CustomLocale = _CustomLocale;
  export type Locale = _Locale;

  export namespace Options {
    export type Options = _Options;
    export type Hook = _Hook;
    export type HookKey = _HookKey;
    export type ParsedOptions = _ParsedOptions;
    export type DateLimit = _DateLimit;
    export type DateOption = _DateOption;
    export type DateRangeLimit = _DateRangeLimit;
    export type Plugin = _Plugin;
  }
}

export = flatpickr;

converted to F# file as

// ts2fable 0.4.0
module rec Fable.Import.Flatpickr
open System
open Fable.Core
open Fable.Import.JS

type FlatpickrFn = ./src/types/instance.FlatpickrFn //incorrect F# syntax
type Instance as _Instance = ./src/types/instance.Instance as _Instance
type Options as _Options = ./src/types/options.Options as _Options
type Hook as _Hook = ./src/types/options.Hook as _Hook
type HookKey as _HookKey = ./src/types/options.HookKey as _HookKey
type ParsedOptions as _ParsedOptions = ./src/types/options.ParsedOptions as _ParsedOptions
type DateLimit as _DateLimit = ./src/types/options.DateLimit as _DateLimit
type DateOption as _DateOption = ./src/types/options.DateOption as _DateOption
type DateRangeLimit as _DateRangeLimit = ./src/types/options.DateRangeLimit as _DateRangeLimit
type Plugin as _Plugin = ./src/types/options.Plugin as _Plugin
type MonthsWeekDays as _MonthsWeekDays = ./src/types/locale.MonthsWeekDays as _MonthsWeekDays
type Locale as _Locale = ./src/types/locale.Locale as _Locale
type CustomLocale as _CustomLocale = ./src/types/locale.CustomLocale as _CustomLocale
let [<Import("*","flatpickr")>] flatpickr: FlatpickrFn = jsNative

module flatpickr =

    type Instance =
        _Instance

    type CustomLocale =
        _CustomLocale

    type Locale =
        _Locale

    module Options =

        type Options =
            _Options

        type Hook =
            _Hook

        type HookKey =
            _HookKey

        type ParsedOptions =
            _ParsedOptions

        type DateLimit =
            _DateLimit

        type DateOption =
            _DateOption

        type DateRangeLimit =
            _DateRangeLimit

        type Plugin =
            _Plugin

This is proper nested project. Things are inherited from every where.

@alfonsogarciacaro what will be proper approach for this kind of library. Because converting this kind of library is like porting whole project to F#.

Or we can have mixed approach. Like skip few parts and import few.

kunjee17 avatar Nov 25 '17 13:11 kunjee17

I would probably try to import directly the referenced files ("./src/types/instance", "./src/types/options", "./src/types/locale") and adjust the Import attribute in the exported values as necessary.

alfonsogarciacaro avatar Nov 25 '17 21:11 alfonsogarciacaro

I created #128 to track importing from multiple linked files. This doesn't work yet out of the box, but thanks for the test case.

ctaggart avatar Nov 27 '17 03:11 ctaggart

@ctaggart I was trying ts d files bundle creator also. But I guess this test case is quite complicated. It is having nested dependency and that is causing issue to make single index.d.ts file even for typescript bundler. I ll try to find of some easier one over here.

kunjee17 avatar Nov 27 '17 04:11 kunjee17