(WIP) Opinionated typed JavaScript dialect for those who hate the loosey-goosey nature of TypeScript (and JavaScript)
- Rust 100%
| src | everything | |
| .gitignore | everything | |
| Cargo.lock | everything | |
| Cargo.toml | everything | |
| README.md | this is opt in now | |
StricterScript
Disclaimer: Nothing is implemented yet.
Opinionated typed JavaScript dialect for those who hate the loosey-goosey nature of TypeScript (and JavaScript).
- Stricter typing system: No unchecked assertions; No surprises.
- Object types are exactly as is unlike in TypeScript where objects may contain extra fields. If you need it for whatever reason, add
...at the end of the object type.
- Object types are exactly as is unlike in TypeScript where objects may contain extra fields. If you need it for whatever reason, add
- Language modifications that removes historical baggages of JavaScript.
- Operator overloading
- Prototype extension without pollution
- Use JavaScript and TypeScript libraries like you never left the ecosystem.
Goals
- Use TypeScript syntax as much as possible
- While it's not a superset of JavaScript, it is still nice to closely follow JavaScript for the sake of familiarity. use opt-in option for incompatible changes.
- Unlike TypeScript, StricterScript isn't purely a type-deleted language, it adds to the runtime.
asand!inserts runtime assertionisoperator for checking a value against a type- Stricter row polymorphism for object types instead of subtyping
- Exhaustive destructuring, add
...at the end for non-exhaustive destructuring - Thrown exceptions are typed
- All unions are discriminated
- Classes are nominally typed: Duck typed for inheritance, I guess subtyping isn't avoidable
exactly Classfor the exact class and not the inheriting classinternalfor fields accessible only in the module
- Interface implementation are required to be explicit, fields are named
Interface.methodin the implementing class. Noimplementskeyword needed.Thisfor type ofthiswithexactly Thisprivatefield implementation to avoid name clashing. For access,this[method of Interface],Interface.method(this, ...),Interface.value.get(this), orInterface.value.set(this, value)are used instead.- Implementation to third-party classes without prototype pollution, requires
privateimplementation. These are named and then exported. Modules that import it will use the implementation.
- Opt-in prototype extension with no actual prototype pollution. These are named and then exported. Modules that import it will use the extension.
- Operator overloading via interfaces
- Prelude system: Interface implementation to third-party classes and prototype extension are opt-in per module. The prelude system makes opt-ins implicit for all modules in a project.
- All of Stage 3 proposals
Opt-in Language Modification
- Use
==for strict reference equality and===for deep equality typeof nullis"null"- Treat
nullandundefinedas the same type, preferringnull - Enable pattern matching on
switch case - Proposals
Interoperability with TypeScript and JavaScript
There are incompatible types between TypeScript and StricterScript. Interoperability is limited. When using opt-in language modification, be careful as those doesn't apply in TypeScript and JavaScript.
- There is no gradual typing within StricterScript, it is always strongly typed
- Interoperability with TypeScript and JavaScript typed with JSDoc
- Optional automatic assertion for untrusted typed imports
- Interoperability with untyped JavaScript
- JavaScript to StricterScript will have assertion enforced
- StricterScript to JavaScript:
- Assertions are automatically added
privateand other similar fields will be unexported for extra privacy- Convenience methods are exported such as
Type.isandType.as