I am following instructions from the this answer, but cannot make the solution work.
Overview
I want to use import { Type } from "Module"
instead of /// <reference path="..." />
Structure
-app\ -ViewModel.ts -Program.ts
ViewModel.ts
export module Demo { export class ViewModel { constructor(public test: string) { } } }
Program.ts
import { ViewModel } from "ViewModel";
Module 'C:/DemoApp/app/ViewModel' has no exported member 'ViewModel'.
and...
Only 'amd' and 'system' modules are supported alongside --outFile.
Goal
I want to be able to reference dependencies so that they compile to a single file in order.
If I add "module": "system"
I still get the 1st of the aforementioned errors.
As per the 1st solution, I do not want to lose namespaces.
Use named exports to export a function in TypeScript, e.g. export function sum() {} . The exported function can be imported by using a named import as import {sum} from './another-file' . You can use as many named exports as necessary in a single file.
To export a constant in TypeScript, we can use the export keyword. export const adminUser = { //... }; to export the adminUser constant.
TypeScript supports export = to model the traditional CommonJS and AMD workflow. The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum.
The TypeScript declares module is one of the modules and keyword it is used for to surround and define the classes, interfaces; variables are also declared it will not originate with the TypeScript like that module is the set of files that contains values, classes, functions/methods, keywords, enum all these contains ...
Remove the line below from your statement
export module Demo
and use it like
export class ViewModel { constructor(public test: string) { } }
Edit: For namespace, just do something like
namespace Demo { export class ViewModel { constructor(public test: string) { } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With