Skip to content

Suggestion: Allow type and value parameters for modules #2625

Closed
@zpdDG4gta8XKpMCd

Description

@zpdDG4gta8XKpMCd

Consider a situation when each class and function in the module depends on the same type/value parameters:

// current
module foo {
   export class C<a> {
      value: a;
      constructor(private areEqual: (one: a, another:a) => boolean) { /*...*/ } 
   }
   export function f1<a>(areEqual: (one: a, another: a) => boolean, ones: a[], anothers: a[]) : boolean {
       // ...
   }
   export function f2<a>(areEqual: (one: a, another: a) => boolean, values: a[], sample: a): number[] {
       // ...
   }
}

It would be awesome if such parameters went to the module level and were resolved at importing

// suggested
module foo<a>(areEqual: (one: a, another: a) => boolean) {

   export class C {
      value: a;
   }

   export function f1(ones: a, anothers: a): boolean {
      //...
   }
   export function f2(values: a[], sample: a): number[] {
      //...
   }
}



import foo = require('foo')((one: Date, another:Date) => one.getTime() === another.getTime());

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionOut of ScopeThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions