PHP Rocks
Typescript runtime import - Druckversion

+- PHP Rocks (https://www.php-rocks.de)
+-- Forum: HTML, CSS, Usability und Barrierefreiheit (https://www.php-rocks.de/https://www.php-rocks.de/forum/11-html-css-usability-und-barrierefreiheit.html)
+--- Forum: JavaScript / JavaScript Frameworks / Ajax (https://www.php-rocks.de/https://www.php-rocks.de/forum/13-javascript-javascript-frameworks-ajax.html)
+--- Thema: Typescript runtime import (/https://www.php-rocks.de/thema/115-typescript-runtime-import.html)



Typescript runtime import - Till - 15.10.2016

Hallo,
ich möchte eine Variable/ein require in einem typescript zur laufzeit verfügbar machen, OHNE ein require (export/import) zur compiletime.
(Mir ist klar das ts nicht dazu gedacht ist, und laut infos alle files zur compiletime verfügbar sein sollten im Idealfall, ich möchte es aber trotzdem (in einigen (Test-)Fällen z.B.))

Nach etwas lesen und testen habe ich nun eine Lösung, möchte aber hier fragen ob es andere/bessere Lösungen gibt, bzw. Meinungen/Erfahrungen hören.
(z.B. ohne die imports zu deklarieren um z.B. existierende javascripts einzufügen)

frdl ist in meinem Beispiel eine zu importierende globale variable (namespace) (hat u.a. eine require Methode)
Code:
declare var frdl : any;
...
function describe(auto: Fahrzeug) {
 ...
 frdl.alert.log('(c) Taken from: http://www.peterkroener.de/typescript-teil-1-die-fakten/', 'log', 0);        
}
Ohne die Deklaration am Anfang mag das script zwar laufen, der compiler wirft aber eine Meldung.

Ich bin mir auch noch nicht ganz sicher über die default libs:
https://github.com/niutech/typescript-compile
https://github.com/Microsoft/TypeScript/tree/master/lib

Test : http://webfan.de/cdn/application/test/typescript.html

mfg


RE: Typescript runtime import - Till - 24.10.2016

Sorry, mir war was dazwischen gekommen.
Also,... bin nun etwas weiter, RTFM:
  • lib.d.ts
  • global.d.ts
  • import / export
  • custom module loader
  • // <reference...

Ich nehme nun nur die minimale lib.d.ts vom typescript-compile node-module und verwende meinen eigenen module loader frdl.require, die exports vom src script sind verfügbar in module.parent im inline script:
var IMPORTS = module.parent;

https://github.com/frdl/-Flow/blob/master/cdn/frdl/flow/ui/frdl-ui.js#L624
Header derzeit: http://frdl.webfan.de/cdn/application/webfan/node_modules/webfan/frdl.d.ts.txt
Test: http://webfan.de/cdn/application/test/typescript.html