-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems with definitions imported across multiple .d.ts files (re pixi.js v6) #413
Comments
Maybe you want this part in readme You can also use In below sample: All the related ts files in npm packages uifabric and office-ui-fabric-react will be compiled to
|
I have a similar issue with G6 I tried the 'office-ui' sample above and it works fine. However the type of import references being used in G6 (and Pixi) don't seem to work with ts2fable current version (compiled from source). Here is the root TS file for G6: import G6 from '@antv/g6-pc';
export * from '@antv/g6-pc';
export default G6;
export declare const version = "4.3.4"; G6 TS references are not relative (or maybe the "@" character is causing issues). ReactXP (which works in ts2fable) has relative references: import * as ReactXP from './web/ReactXP';
export = ReactXP; Is there a quick workaround that I can try. PS: Is there a way to debug F# code in ts2fable. I am running "Watch Test" with mocha but breakpoints are not accepted by vscode. |
According to this [corrected] article. Non-relative path import requires the "tsconfig-paths" module. I have added the following to package.json:
Also needed is a CompilerOptions setting called "paths". I am assuming that the place to do this is in bridge.fs but I can't seem to construct a "MapLike<ResizeArray>" value that "paths" requires. let createDummy tsPaths (sourceFiles: SourceFile list) =
let options = jsOptions<CompilerOptions>(fun o ->
o.target <- Some scriptTarget
o.``module`` <- Some ModuleKind.CommonJS
o.paths <- fun s ->
Some
[
"src/*", ResizeArray["src/*"]
]
) Any suggestions? |
Looks like one has to implement MapLike<_> as it is an interface type TsPaths(vs:Dictionary<string,ResizeArray<string>>) =
interface MapLike<ResizeArray<string>> with
member _.Item with get(v) = vs.[v] and set key value = vs.[key] <- value but still not sure about what the the path entries need to be to make this all work ... |
After much internet search, the bottom line is that the new style of import references in TS is not a javascript standard and hence it is not universally supported. In particular node does not support such references, out of the box. The "tsconfig-paths" package supports the remapping of TS references to relative references, however, its implementation is not complete. ts2fable internally loads the typescript compiler (in bridge.fs) to find the imports. It is not clear to me how to enable "tsconfig-paths" for the internally hosted compiler. I tried to require "tsconfig-paths/register" for ts2fable but it did not seem to work. Admittedly I am not the expert in this area so instead of spending more time on g6, I switched to another graph library, cytoscape. The .ts definitions in DefinitelyTyped for cytoscape were processed correctly by ts2fable. I have a feeling that fable users will increasingly run into this issue and hopefully more knowledgeable members of the community can find a solution. |
in short: ts2fable doesn't seem to really handle re-exports at all.... In the example with To test this with
In fact ts2fable doesn't handle some of the stuff in
So yeah....unfortunately no real re-export dependency handling at all (sub-dir or somewhere else) -- just the option to export everything. I think supporting this would require some major work. But might be reasonable. "Collection"-packages aren't that uncommon (D3 is quite similar). Some more stuff:
About Breakpoints:
That should break when reaching your breakpoint. Though: Debugging isn't that nice: quite a lot of code is Javascript (like all Fable implementations like List). And breakpoint locations are sometimes strange (inside of strings?). But breakpoints per se should work. Note: Just to be sure every dependency is downloaded, run |
@Booksbaum thanks for your analysis. I don't know enough about the node.js/javascript/ts ecosystem so your comments are probably right. I was expecting/hoping that the discovery of the referenced modules could be delegated to the TS compiler. Maybe it is just a matter of being able to supply the right parameters (e.g. a tsconfig.json file)? PS |
Unfortunately it's not just that simple. Resolving a dependency is hopefully something the TS Compiler can do. But then we still need to recognize re-exports (-> dependencies that get exported again) and process the dependency files correctly (translating AND putting the generated code in the correct place).
My bad: -> Fixed in master With this VS Code Breakpoints should work with source maps (-> F# code). |
I ran into this issue when trying to update fable-pixi from pixi.js v5 to v6.
pixi.js type definition files have code like this:
which gets translated by ts2fable into this:
which is not valid. I'm actually not sure what the correct behavior here is, because the original fable-pixi handles this in a way that seems hand-written (see Fable.Pixi.js).
Here is the script I ran from within the ts2fable/ project dir:
Also, this generated everything in a single module. It was unclear from the ts2fable docs if there was a simple way to put the output of each file into its own module - maybe it just means running ts2fable separately and gluing them together manually?
The text was updated successfully, but these errors were encountered: