question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use IExport generated by ts2fable?

See original GitHub issue

sorry for dumb question. But how to use Static type in above case. Means that is also abstract class. So, should I try createEmpty or jsoption for it. I tried jsoptions that did’t work. need to check create empty though.

Below is simple reference code

type [<AllowNullLiteral>] IExports =
    abstract HelloResponse: HelloResponseStatic
    abstract Hello: HelloStatic

type [<AllowNullLiteral>] IReturn<'T> =
    abstract createResponse: unit -> 'T

type [<AllowNullLiteral>] IReturnVoid =
    abstract createResponse: unit -> unit

type [<AllowNullLiteral>] HelloResponse =
    abstract result: string with get, set

type [<AllowNullLiteral>] HelloResponseStatic =
    [<Emit "new $0($1...)">] abstract Create: unit -> HelloResponse

type [<AllowNullLiteral>] Hello =
    inherit IReturn<HelloResponse>
    abstract name: string with get, set
    abstract createResponse: unit -> unit
    abstract getTypeName: unit -> unit

type [<AllowNullLiteral>] HelloStatic =
    [<Emit "new $0($1...)">] abstract Create: unit -> Hello

So, how to create Hello out of HelloStatic?

PS: On side note. In Hello type createResponse type is coming wrong. It should be HelloResponse. For reference below is TypeScript code.

export interface IReturn<T>
{
    createResponse() : T;
}

export interface IReturnVoid
{
    createResponse() : void;
}

export class HelloResponse
{
    result: string;
}

// @Route("/hello")
// @Route("/hello/{Name}")
export class Hello implements IReturn<HelloResponse>
{
    name: string;
    createResponse() { return new HelloResponse(); }
    getTypeName() { return "Hello"; }
}

I am using latest 0.4 version of ts2fable. If you want I can file another issue for same.

cc/ @MangelMaxime

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jgrundcommented, Jan 11, 2018

Yeah, was my mistake. I was missing the module wrapper around the declarations.

1reaction
kunjee17commented, Jan 11, 2018

@jgrund it depends actually. If there is no global export then there will be no let binding . You have to create it by your self in that case. Else it will be generated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

fable-compiler/ts2fable-exports
All branches are auto-generated by ts2fable. Contribute to fable-compiler/ts2fable-exports development by creating an account on GitHub.
Read more >
ts2fable-json-export - npm Package Health Analysis
Is ts2fable-json-export safe to use? The npm package ts2fable-json-export was scanned for known vulnerabilities and missing license, and no issues were found.
Read more >
ts2fable/README.md
The CDN for ts2fable. ... 22, You can also use `--export`(or `-e`) option to collect from multiple `tsfiles` ... 94, removed from the...
Read more >
Let's write Fable bindings for a JS library
Learn about writing Fable Bindings for a Javascript or Typescript library. See the article for a list of common scenarios and examples.
Read more >
Export all interfaces/types from one file in TypeScript project
The only way I think that might work, is to import the foo.d.ts/bar.d.ts types into index.d.ts and then in turn export them from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found