0

I'm trying to create my first Typescript definition file. The subject code is filename.js (index.js):

module.exports = {
  extension: extension,
  basename: basename,
  removeSuffix: removeSuffix,
  removeSuffixWithDelimiter: removeSuffixWithDelimiter,
  appendSuffix: appendSuffix,
  appendSuffixWithDelimiter: appendSuffixWithDelimiter,
  directoryName: directoryName
}
function extension(filename) {}
function basename(filename) {}
function removeSuffix(filename) {}
function removeSuffixWithDelimiter(delimiter, filename) {}
function appendSuffix(suffix, filename) {}
function appendSuffixWithDelimiter(suffix, delimiter, filename) {}
function directoryName(filename) {}

The definition (index.d.ts) file I have so far:

declare module "filename.js" {
  export function extension(filename: string): string;
  export function basename(filename: string): string;
  export function removeSuffix(filename: string): string;
  export function removeSuffixWithDelimiter(delimiter: string|number, filename: string): string;
  export function appendSuffix(suffix: string, filename: string): string;
  export function appendSuffixWithDelimiter(suffix: string, delimiter: string|number, filename: string): string;
  export function directoryName(filename: string): string;
}

This works well enough (auto complete works in my editor), but I get a compile error:

index.ts(21,29): error TS2656: Exported external package typings file 'filename.js/index.d.ts' is not a module. Please contact the package author to update the package definition.

What does this error mean (new to Typescript), and more importantly, how should I modify my definition to make it more correct?

3
  • Have you been able to fix this? I'm having the same issue. Commented Jul 2, 2016 at 23:28
  • @emzero no I haven't been able to so far Commented Jul 2, 2016 at 23:35
  • Hopefully it will be fixed in TS 2.0 Commented Jul 3, 2016 at 2:03

1 Answer 1

1

Definition file for the data provided by you can be:-

declare module customTypings{
 interface filename{
  extension(filename: string): string;
  basename(filename: string): string;
  removeSuffix(filename: string): string;
  removeSuffixWithDelimiter(delimiter: string|number, filename: string): string;
  appendSuffix(suffix: string, filename: string): string;
  appendSuffixWithDelimiter(suffix: string, delimiter: string|number, filename: string): string;
  directoryName(filename: string): string;
 }
}

You can use this typing file by specifying:-

/// <reference path="pathName" />

See if it works.

For more info refer already created .d.ts files. e.g. angular-material.d.ts

Sign up to request clarification or add additional context in comments.

3 Comments

Same error, unfortunately. Also your example doesn't provide accurate auto-completions.
did you saw already created .d.ts file. may be we should refer those files when creating our so that we don't include any extra thing inside our code.
I included my index.d.ts file in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.