We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
this
Some unaddressed concerns in PR.
Differences between parameter/this type guards
Parameter type guards check against type of parameters
this type-guards tied to a signature
`this type-guards allowed on properties
Narrowing logic identifies when a method gets called or a property access is performed.
Check for a this-type guard, which will narrow the LHS of a property access.
Allows an identifier or this on the LHS of the is operator.
is
A this-based type guard is assignable if the
boolean is assignable to this-based type guard on member.
boolean
interface Foo { isVar: this is Bar } var foo: Foo; foo.isBar = true; // kosher
this type predicates for properties don't allow predicates for broader types to be assigned to predicates of more specific types.
get
Promoted type guards to an actual type.
We can now make inferences for type parameters based on type predicate types.
Useful for functions like filter.
filter
function isNumber(x: any): x is number { return typeof x === "number"; } let x = [1, 2, "a", "b"]; let y = x.filter(isNumber); // type is 'number[]'
It would be nice if isNumber didn't need to be declared.
isNumber
let x = [1, 2, "a", "b"]; let y = x.filter(() => typeof x === "number"); // type is 'number[]'
Going off-topic.
Let's go back to assignability rules.
We'll need to go back and check a little more, because certain people (like myself) signed off on it before a design meeting.
super
User wants to get value of accessor via super.value from superclass.
super.value
Problem is we don't distinguish between getters and property descriptors.
This sort-of works in ES2015, but not actually.
class { value: number; constructor() { this.value = 10; } } class Derived extends Base { foo() { return super.value; } }
foo
undefined
Could write a fix to lookup if a getter exists at runtime, looks really gross.
super.prop
super.prop()
In ES6, we should probably allow this.
Potential emit:
class A { foo; bar() { } } class B extends A { zzz() { let y = super.foo; } }
to ES2015
class A { foo; bar() { } } class B extends A { zzz() { var y = (_a = Object.getOwnPropertyDescriptor(_super.prototype, 'foo'), a && (a.get ? _a.get.call(this) : _a.value); var _a; } }
this.foo
What about element access syntax (i.e. super[4 + 3])?
super[4 + 3]
ES6 vs ES5
What about assignment to a property on super?
class B extends A { zzz() { super.foo = 1; // (1) this.foo = 1; // (2) } }
(1)
(2)
Resolution: 👍 (need to propose a new emit)
__proto__
null
string
Two issues for this:
Is this useful?
We do hacks like this in the compiler to differentiate strings from actual paths.
But these types don't exist at runtime.
Aside: thanks to string literal types, you can do even more crazy tagging stuff.
type Meters = number & "Meters"; type Feet = number & "Feet"
Number
String
Resolutions
But, this is just supporting a hack, so we should really consider giving people a better mechanism.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
this
type guards (#5906)Some unaddressed concerns in PR.
Differences between parameter/this type guards
Parameter type guards check against type of parameters
this
type-guards tied to a signature`this type-guards allowed on properties
Narrowing logic identifies when a method gets called or a property access is performed.
Check for a
this
-type guard, which will narrow the LHS of a property access.Allows an identifier or
this
on the LHS of theis
operator.A
this
-based type guard is assignable if theboolean
is assignable tothis
-based type guard on member.this
type predicates for properties don't allow predicates for broader types to be assigned to predicates of more specific types.boolean
, so that should be allowed.get
accessors might make this too confusing.Promoted type guards to an actual type.
We can now make inferences for type parameters based on type predicate types.
Useful for functions like
filter
.It would be nice if
isNumber
didn't need to be declared.Going off-topic.
Let's go back to assignability rules.
We'll need to go back and check a little more, because certain people (like myself) signed off on it before a design meeting.
Get accessors via
super
(#4465)User wants to get value of accessor via
super.value
from superclass.Problem is we don't distinguish between getters and property descriptors.
This sort-of works in ES2015, but not actually.
foo
returnsundefined
.undefined
.Could write a fix to lookup if a getter exists at runtime, looks really gross.
super.prop
without using it as a call (i.e.super.prop()
).In ES6, we should probably allow this.
Potential emit:
to ES2015
this.foo
doesn't check the instance.What about element access syntax (i.e.
super[4 + 3]
)?ES6 vs ES5
What about assignment to a property on
super
?(1)
and(2)
actually do completely different things!(1)
actually sets a descriptor onthis
(!!??)Resolution: 👍 (need to propose a new emit)
super
should be allowed in a computed property (when nested in a class) (#6038)super
refers to thesuper
of the containing class.super
in object literal causes error (#5441)__proto__
is valid.__proto__
is set tonull
.__proto__
forsuper
?this
.Intersection types (intersecting with
string
) are not valid index signature typesTwo issues for this:
string
string
, when indexing value has astring
index signature.Is this useful?
We do hacks like this in the compiler to differentiate strings from actual paths.
But these types don't exist at runtime.
Aside: thanks to string literal types, you can do even more crazy tagging stuff.
Number
andString
types.Resolutions
But, this is just supporting a hack, so we should really consider giving people a better mechanism.
The text was updated successfully, but these errors were encountered: