Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Design Meeting Notes for 1/22/2016 #6614

Closed
mhegazy opened this issue Jan 25, 2016 · 0 comments
Closed

Design Meeting Notes for 1/22/2016 #6614

mhegazy opened this issue Jan 25, 2016 · 0 comments
Labels
Design Notes Notes from our design meetings

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Jan 25, 2016

Declaring ambient external modules

Related issues:

Problems:

  • Can not easily specify a loader extension for json or css (e.g. `json!a.json); currnetlly every reousere needs to have its own declaration
  • Problem with migrating to .ts, with modules that do not have typings, and users just want to get by

Proposal:

  • Allow for short hand module declarations:

    declare module "foo";

    to be equivalent to:

    declare module "foo" {
        var _temp: any;
        export = _temp;
    }
  • Allow module names to have a wildcard character and match that in lookup

    declare module "json!*" {
        let json: any;
        export default json;
    }
    
    import d from "json!a/b/bar.json";
    // lookup:
    //    json!a/b/bar.json
    //    json!*
  • Additional the module "*" would allow for matching all unknown modules in the system, which can be used as a way to suppress all missing module errors

    declare module "*";
    
    import d from "some\unknown\module"; // no error, d is any
  • Report no-implicit-any errors for modules declared using the shorthand notaion
    Open issue: is this reported on declaration or use sites

Readonly properties

Suggestion

PR

Design

A property is allowed to have one of three states:

  • readonly
  • unknown
  • mutable

readonly properties are declared using readonly modifier, or as getters with no setters.
mutable properties are
readonly properties can not be assigned to if accessed directly. readonly properties are assignable to properties deemed "unknown", but not to mutable properties.

The rational here is ppl today do not have a way of expressing readonly, so existing typings do not really mean "mutable" by default. enforcing a default of mutability on these definitions will make using them with exiting typings much harder.
we still want to catch the most blatant violations of readonly, i.e. writing to a readonly property.

So:

interface I {
    x: number;    
}

class C {
    get x() { return 1; }
}

var c = new C();
var i: I;

c.x  = 1; // error, assigning to a readonly property

i = c; // No error, c is assignable to i

Next steps

  • Merge Readonly properties and index signatures #6532

  • Add the mutable modifier

  • Look into a readonly type operator to generate a readonly version of a type e.g.

    var x: readonly { a: string[] }
    x.a = []; // error;
    x.a.push(..); // error
    x["b"] = 0; // error
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Design Notes Notes from our design meetings
Projects
None yet
Development

No branches or pull requests

1 participant