I have created a definition file (d.ts) from my typescript project using the --declaration argument from the tsc compiler.
But this generated definition file apparently not work when i try to publish the package with the property typings at the npm package.json. I have created another project to test it.
It complains with the message: "Exported external package file typings file '...d.ts' is not a module. Please contact the package author to update the package definition".
This are my source files:
MyInterface.ts
export interface MyInterface
{
MyProperty: string;
}
MyClass.ts
import {MyInterface} from './MyInterface';
export class MyClass implements MyInterface
{
get MyProperty(): string
{
return "MyString";
}
}
MyInheritedClass.ts
import {MyClass} from './MyClass';
export class MyInheritedClass extends MyClass
{
public MyMethod(): number
{
return 1;
}
}
The tsc command is this:
tsc MyClass.ts MyInterface.ts MyInheritedClass.ts --declaration -t es5 -outFile "mydefinition.js" --module "system"
This is the generated definition:
mydefinition.d.ts
declare module "MyInterface" {
export interface MyInterface {
MyProperty: string;
}
}
declare module "MyClass" {
import { MyInterface } from "MyInterface";
export class MyClass implements MyInterface {
MyProperty: string;
}
}
declare module "MyInheritedClass" {
import { MyClass } from "MyClass";
export class MyInheritedClass extends MyClass {
MyMethod(): number;
}
}
Is there another thing i have to do or the generated definition supposedly not work in the package.json typings ??
Update for more details:
The scenario is that i have 2 projects:
The First project is where i generate the library where i will publish to npm, and the package.json is where i put the typings property linking to the mydefinition.d.ts file generated by the tsc -d command.
The Second project i create to test the first one by adding the package (with typings) generated.
A link with the 2 projects and another links for the scenario :
https://github.com/jvitor83/typings-packagejson
I think the problem is with the "Your definition files should be written as external modules" at the first link. But i want to know if there is a way to get those definitions generated to put at the typings property of the package.json.
To reproduce the problem:
Clone this repo: https://github.com/jvitor83/test-typings-packagejson
Do 'npm install', open with VSCode and go to the file 'src/test.ts'.


typings.json? - Radoslav Stoyanovpackage.jsonin thescriptssection you declare a script for typings and after that you can use it to install the type definitions you want like this:npm run typings -- install jasmine --ambient --save- Radoslav StoyanovsystemtoCommonJS. - aleung