fable-compiler / Fable

F# to JavaScript, TypeScript, Python, Rust and Dart Compiler
http://fable.io/
MIT License
2.92k stars 300 forks source link

implicit conversion import error when DateTime promoted to DateTimeOffset #3908

Open joprice opened 3 weeks ago

joprice commented 3 weeks ago

Description

When a DateTime gets implicitly converted to a DateTimeOffset, the import op_Implicit is missing in the js library:

SyntaxError: The requested module 'https://fable.io/repl/js/repl/fable-library-js/DateOffset.js' does not provide an export named 'op_Implicit' (at 0110e4f1-0010-49d1-b621-0c084f71ae75:62:10)

Repro code

open System

let _: DateTimeOffset = DateTime.UtcNow.Date
import { op_Implicit } from "fable-library-js/DateOffset.js";
import { utcNow, date } from "fable-library-js/Date.js";

op_Implicit(date(utcNow()));

Related information

MangelMaxime commented 3 weeks ago

I think we can just alias to op_Implicit to fromDate:

// Write code or load a sample from sidebar
open System

let _: DateTimeOffset = DateTime.UtcNow.Date

let x = DateTimeOffset(DateTime.UtcNow.Date)
import { fromDate, op_Implicit } from "fable-library-js/DateOffset.js";
import { utcNow, date } from "fable-library-js/Date.js";

op_Implicit(date(utcNow()));

export const x = fromDate(date(utcNow()));

We can do it directly in the Replacement module to avoid having a new function in fable-library, I will have a look at it later.