This is a minimal Fable sample application based off of the Fable dotnet template.
- Run
npm install
. - Run
dotnet build src
. - Run the app with
node_modules\.bin\webpack-dev-server
.
-
Observe the file is normal F#, with modules and open statements.
-
We can get a reference to a DOM element using standard DOM browser functions. These are simple F# wrappers around the browser.
-
This includes event handlers.
-
We can even use
window.alert
! -
We can even use some BCL methods that can magically "transpiled" to equivalent JS methods e.g. DateTime.
-
We can reference modules of other JS files e.g. NPM packages easily using the
import
function -
We can go even lower and use the
Emit
attribute. -
Or we can create an interface to match the JS module.
-
If we're feeling dangerous we can do complete dynamic typing using the
?
operator.
There is a website called TS2Fable which attempts to massage TS definitelytyped interfaces into F#.
See also here for more details.