Skip to content

Latest commit

 

History

History
89 lines (68 loc) · 1.78 KB

typescript-module-declaration.md

File metadata and controls

89 lines (68 loc) · 1.78 KB

filenames-simple/typescript-module-declaration

This rule checks the filename includes name of declared module.

Configuration example

{
  "plugins": ["filenames-simple"],
  "rules": {
    "filenames-simple/typescript-module-declaration": "error"
  }
}

Available options

No options are provided.

Rule details

Basic

  • espree.d.ts

    // OK
    declare module 'espree' {
      export function parse(code: string, options?: any): Node;
    }
  • eslint.d.ts

    // NG: The filename does not include the declared module name. We recommend renaming it to `espree.d.ts`.',
    declare module 'espree' {
      export function parse(code: string, options?: any): Node;
    }
  • node.d.ts

    // OK: More than two modules are declared in the target file.
    // https://www.typescriptlang.org/docs/handbook/modules.html#ambient-modules
    declare module 'url' {
      export interface Url {
        protocol?: string;
        hostname?: string;
        pathname?: string;
      }
    
      export function parse(urlStr: string, parseQueryString?, slashesDenoteHost?): Url;
    }
    
    declare module 'path' {
      export function normalize(p: string): string;
      export function join(...paths: any[]): string;
      export var sep: string;
    }

With path separator, wildcard

  • dayjs/locale/index.d.ts

    // OK: The dirname includes the name of declared module.
    declare module 'dayjs/locale/*' {
      namespace locale {
        interface Locale extends ILocale {}
      }
    
      const locale: locale.Locale;
    
      export default locale;
    }
  • json.d.ts

    // OK
    // https://www.typescriptlang.org/docs/handbook/modules.html#wildcard-module-declarations
    declare module 'json!*' {
      const value: any;
      export default value;
    }