Skip to content

Official coding practice is not used yourself in declaration files #13882

@falsandtru

Description

@falsandtru

Don't write overloads that differ by type in only one argument position:

/* WRONG */
interface Moment {
utcOffset(): number;
utcOffset(b: number): Moment;
utcOffset(b: string): Moment;
}
Do use union types whenver possible:

/* OK */
interface Moment {
utcOffset(): number;
utcOffset(b: number|string): Moment;
}

https://github.com/Microsoft/TypeScript-Handbook/blob/master/pages/declaration%20files/Do's%20and%20Don'ts.md#use-union-types

TypeScript Version: master

Code

https://github.com/Microsoft/TypeScript/blob/master/src/lib/es5.d.ts#L330-L340

Expected behavior:

    match(regexp: string | RegExp): RegExpMatchArray | null;

Actual behavior:

    /**
      * Matches a string with a regular expression, and returns an array containing the results of that search.
      * @param regexp A variable name or string literal containing the regular expression pattern and flags.
      */
    match(regexp: string): RegExpMatchArray | null;

    /**
      * Matches a string with a regular expression, and returns an array containing the results of that search.
      * @param regexp A regular expression object that contains the regular expression pattern and applicable flags.
      */
    match(regexp: RegExp): RegExpMatchArray | null;

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions