10/19/2012
Fundules, clodules and lightweight mixins. Motivations:
- Properties on functions
- function foo() {}
- foo.data = "hello";
- Nested classes
- class Geometry {}
- class Geometry.Point extends Geometry {}
- Namespace interfaces
- interface jQuery.AjaxSettings {}
- Concepts in TS:
(T: Types, N: Namespace, P: Properties)
- Interfaces
- Modules
- Classes
- Functions
- Variables
- Names can be:
- Types
- Things that can go after colon
- Namespaces:
- Things that can contain namespaces or types
- N.N.N.T
- Properties
- Things that are in the value scope referring to things at runtime
- P.P.P.P
interface jQuery {
}
module jQuery {
interface XHR { … }
}
var jQuery: …;
- Proposal:
- Module, classes, funciton can all contribute to the same name
- If only 'module' definitions contribute to a name, it can be spread across files
- If any class and/or function definition contributes to a name, all contributions must be in the same file
- Allow dotted named declarations
- Consider: When we know a name exists, don't generate the potential creation code
- Bring back anonymous modules??
// IIFE
module {
// 1000 lines of code
class Bar implements SignalR { }
export interface SignalR {}
export interface $ {
signalR: SignalR;
}
$.signalR = new Bar();
}
- Brands
- Provide:
- Know it was created by your constructor
- This isn't that important
- Captures knowledge of privates
- This is partly handled for free given privates as members of the type
- But need to make sure privates have unique names (GUID attached)
- Summary?
- Namespacing types
- Extending functions/classes with modules
- Getting rid of brands
- Open ended classes
- Anonymous modules