TypeScriptCompiler
TypeScriptCompiler copied to clipboard
Support for Imports
It would be great, if Typescript projects that are using the import
syntax to import variables, functions, classes or types could be compiled with tsc.
I tried the following:
import x from "./x";
And then tried to compile it, but it failed with "unknown statement type":
➜ tsc git:(main) ✗ ../__build/tsc-ninja/bin/tsc ../example.ts --emit=jit --nogc
unknown statement type
Thoughts?
"Import" is not working for now, it is planned feature for future after generics. But can't say when and how I will implement it.
Would be amazing to have imports
support. Everybody uses imports
but not everybody uses generics
:).
it can be most difficult part of the project. Because it is generated into obj files you can use "export" and "declare" to split code into many files for now
added "/// reference" support in the last commit
Hey @ASDAlexander77 any suggestion on how to use the mentioned /// reference
support?
Eager to start using it!
check the code in TypeScriptCompiler\docs\how\cmake_vulkan\src\ but keep it in mind that compiler is in progress and requires a lot of debugging etc
HI!, is import completed ? will you support import from so in the future?
yes, work is in progress, not sure to which level I will develop it, or how long will it take, but for now I am implementing very basic functionality for "import" (kind of ///
last coomit contains simple implementation of "import" example:
/// <reference path="window.win32.d.ts" />
import "./appwindow";
export class Application {
static appWindow: AppWindow;
export static run() {
this.appWindow = new AppWindow();
}
}
That's an awesome first step @ASDAlexander77.
Do you know if importing types or variables by name would work? Is the /// <reference ...>
tag always required?
Is the /// <reference ...> tag always required?
no, you don't need it if you don't use anything from the referenced file
it seems I still need to improve it not to use "/// <reference ...>"
That's an awesome first step @ASDAlexander77. Do you know if importing types or variables by name would work? Is the
/// <reference ...>
tag always required?
you don't need to use <reference ...> in the last commit
Do you know if importing types or variables by name would work?
not at this moment. and I am not sure if I need to impalement it, as it is not "JVM" and import working differently
"Import" is not working for now, it is planned feature for future after generics. But can't say when and how I will implement it.
Would be great to see, Then we could slap some socket libs to it and roll an HTTP server out ez : ))
If I may? I'd recommend making the import process similar to how
#pragma link library
works, allowing us to include C++ libs on demand too if possible? as there are existing tools available c++ to javascript (like emscripten) so producing types shouldn't be an issue.
This way we might get language interoperability at some extent?
I think I will do import the way how C++ include DLL files
I think also a possibility for implementing imports is to bundle it using existing bundlers such as esbuild and then just compile?
I can't see why this wouldn't work if bundlers would generate/output TS files.
esbuild
well, when u compile every file you get OBJs files, then "Link" will join them into 1 file. Seems what esbuild does.
added additional way to import share libraries
added additional way to import share libraries
Try import get the error
Can u share your source code and compilation steps?
Can u share your source code and compilation steps?
// shared.ts
export default class Service {
}
// use_shared.ts
import Service from "./shared";
class MyComponent {
constructor(public Service: Service) {
}
method(x: this) {
}
}
function main()
{
const myComponent = new MyComponent(null);
print("done.");
}
run D:\tsc\tsc.exe --opt --emit=jit --nogc .\src\use_shared.ts
os: win10 version: v0.0-pre-alpha40
you need to use latest from main
branch. I am planning to release new build after improving "wasm" support