-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix flow control in the presence of simplifiable types
- Loading branch information
Showing
5 changed files
with
224 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
tests/baselines/reference/thisIndexOnExistingReadonlyFieldIsNotNever.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
//// [thisIndexOnExistingReadonlyFieldIsNotNever.ts] | ||
declare class Component<P, S = {}> { | ||
readonly props: Readonly<{ children?: unknown }> & Readonly<P>; | ||
state: Readonly<S>; | ||
} | ||
interface CoachMarkAnchorProps<C> { | ||
anchorRef?: (anchor: C) => void; | ||
} | ||
type AnchorType<P> = Component<P>; | ||
|
||
class CoachMarkAnchorDecorator { | ||
decorateComponent<P>(anchor: P) { | ||
return class CoachMarkAnchor extends Component<CoachMarkAnchorProps<AnchorType<P>> & P, {}> { | ||
private _onAnchorRef = (anchor: AnchorType<P>) => { | ||
const anchorRef = this.props.anchorRef; | ||
if (anchorRef) { | ||
anchorRef(anchor); | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
|
||
|
||
//// [thisIndexOnExistingReadonlyFieldIsNotNever.js] | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
} | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var CoachMarkAnchorDecorator = /** @class */ (function () { | ||
function CoachMarkAnchorDecorator() { | ||
} | ||
CoachMarkAnchorDecorator.prototype.decorateComponent = function (anchor) { | ||
return /** @class */ (function (_super) { | ||
__extends(CoachMarkAnchor, _super); | ||
function CoachMarkAnchor() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this._onAnchorRef = function (anchor) { | ||
var anchorRef = _this.props.anchorRef; | ||
if (anchorRef) { | ||
anchorRef(anchor); | ||
} | ||
}; | ||
return _this; | ||
} | ||
return CoachMarkAnchor; | ||
}(Component)); | ||
}; | ||
return CoachMarkAnchorDecorator; | ||
}()); |
76 changes: 76 additions & 0 deletions
76
tests/baselines/reference/thisIndexOnExistingReadonlyFieldIsNotNever.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
=== tests/cases/compiler/thisIndexOnExistingReadonlyFieldIsNotNever.ts === | ||
declare class Component<P, S = {}> { | ||
>Component : Symbol(Component, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 0)) | ||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 24)) | ||
>S : Symbol(S, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 26)) | ||
|
||
readonly props: Readonly<{ children?: unknown }> & Readonly<P>; | ||
>props : Symbol(Component.props, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 36)) | ||
>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --)) | ||
>children : Symbol(children, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 1, 30)) | ||
>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --)) | ||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 24)) | ||
|
||
state: Readonly<S>; | ||
>state : Symbol(Component.state, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 1, 67)) | ||
>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --)) | ||
>S : Symbol(S, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 26)) | ||
} | ||
interface CoachMarkAnchorProps<C> { | ||
>CoachMarkAnchorProps : Symbol(CoachMarkAnchorProps, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 3, 1)) | ||
>C : Symbol(C, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 31)) | ||
|
||
anchorRef?: (anchor: C) => void; | ||
>anchorRef : Symbol(CoachMarkAnchorProps.anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 35)) | ||
>anchor : Symbol(anchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 5, 17)) | ||
>C : Symbol(C, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 31)) | ||
} | ||
type AnchorType<P> = Component<P>; | ||
>AnchorType : Symbol(AnchorType, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 6, 1)) | ||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 7, 16)) | ||
>Component : Symbol(Component, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 0)) | ||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 7, 16)) | ||
|
||
class CoachMarkAnchorDecorator { | ||
>CoachMarkAnchorDecorator : Symbol(CoachMarkAnchorDecorator, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 7, 34)) | ||
|
||
decorateComponent<P>(anchor: P) { | ||
>decorateComponent : Symbol(CoachMarkAnchorDecorator.decorateComponent, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 9, 32)) | ||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22)) | ||
>anchor : Symbol(anchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 25)) | ||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22)) | ||
|
||
return class CoachMarkAnchor extends Component<CoachMarkAnchorProps<AnchorType<P>> & P, {}> { | ||
>CoachMarkAnchor : Symbol(CoachMarkAnchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 11, 14)) | ||
>Component : Symbol(Component, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 0)) | ||
>CoachMarkAnchorProps : Symbol(CoachMarkAnchorProps, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 3, 1)) | ||
>AnchorType : Symbol(AnchorType, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 6, 1)) | ||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22)) | ||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22)) | ||
|
||
private _onAnchorRef = (anchor: AnchorType<P>) => { | ||
>_onAnchorRef : Symbol(CoachMarkAnchor._onAnchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 11, 101)) | ||
>anchor : Symbol(anchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 12, 36)) | ||
>AnchorType : Symbol(AnchorType, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 6, 1)) | ||
>P : Symbol(P, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 10, 22)) | ||
|
||
const anchorRef = this.props.anchorRef; | ||
>anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 13, 21)) | ||
>this.props.anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 35)) | ||
>this.props : Symbol(Component.props, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 36)) | ||
>this : Symbol(CoachMarkAnchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 11, 14)) | ||
>props : Symbol(Component.props, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 0, 36)) | ||
>anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 4, 35)) | ||
|
||
if (anchorRef) { | ||
>anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 13, 21)) | ||
|
||
anchorRef(anchor); | ||
>anchorRef : Symbol(anchorRef, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 13, 21)) | ||
>anchor : Symbol(anchor, Decl(thisIndexOnExistingReadonlyFieldIsNotNever.ts, 12, 36)) | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
|
57 changes: 57 additions & 0 deletions
57
tests/baselines/reference/thisIndexOnExistingReadonlyFieldIsNotNever.types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
=== tests/cases/compiler/thisIndexOnExistingReadonlyFieldIsNotNever.ts === | ||
declare class Component<P, S = {}> { | ||
>Component : Component<P, S> | ||
|
||
readonly props: Readonly<{ children?: unknown }> & Readonly<P>; | ||
>props : Readonly<{ children?: unknown; }> & Readonly<P> | ||
>children : unknown | ||
|
||
state: Readonly<S>; | ||
>state : Readonly<S> | ||
} | ||
interface CoachMarkAnchorProps<C> { | ||
anchorRef?: (anchor: C) => void; | ||
>anchorRef : ((anchor: C) => void) | undefined | ||
>anchor : C | ||
} | ||
type AnchorType<P> = Component<P>; | ||
>AnchorType : Component<P, {}> | ||
|
||
class CoachMarkAnchorDecorator { | ||
>CoachMarkAnchorDecorator : CoachMarkAnchorDecorator | ||
|
||
decorateComponent<P>(anchor: P) { | ||
>decorateComponent : <P>(anchor: P) => typeof CoachMarkAnchor | ||
>anchor : P | ||
|
||
return class CoachMarkAnchor extends Component<CoachMarkAnchorProps<AnchorType<P>> & P, {}> { | ||
>class CoachMarkAnchor extends Component<CoachMarkAnchorProps<AnchorType<P>> & P, {}> { private _onAnchorRef = (anchor: AnchorType<P>) => { const anchorRef = this.props.anchorRef; if (anchorRef) { anchorRef(anchor); } } } : typeof CoachMarkAnchor | ||
>CoachMarkAnchor : typeof CoachMarkAnchor | ||
>Component : Component<CoachMarkAnchorProps<Component<P, {}>> & P, {}> | ||
|
||
private _onAnchorRef = (anchor: AnchorType<P>) => { | ||
>_onAnchorRef : (anchor: Component<P, {}>) => void | ||
>(anchor: AnchorType<P>) => { const anchorRef = this.props.anchorRef; if (anchorRef) { anchorRef(anchor); } } : (anchor: Component<P, {}>) => void | ||
>anchor : Component<P, {}> | ||
|
||
const anchorRef = this.props.anchorRef; | ||
>anchorRef : (CoachMarkAnchorProps<Component<P, {}>> & P)["anchorRef"] | undefined | ||
>this.props.anchorRef : (CoachMarkAnchorProps<Component<P, {}>> & P)["anchorRef"] | undefined | ||
>this.props : Readonly<{ children?: unknown; }> & Readonly<CoachMarkAnchorProps<Component<P, {}>> & P> | ||
>this : this | ||
>props : Readonly<{ children?: unknown; }> & Readonly<CoachMarkAnchorProps<Component<P, {}>> & P> | ||
>anchorRef : (CoachMarkAnchorProps<Component<P, {}>> & P)["anchorRef"] | undefined | ||
|
||
if (anchorRef) { | ||
>anchorRef : (CoachMarkAnchorProps<Component<P, {}>> & P)["anchorRef"] | undefined | ||
|
||
anchorRef(anchor); | ||
>anchorRef(anchor) : void | ||
>anchorRef : (anchor: Component<P, {}>) => void | ||
>anchor : Component<P, {}> | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
tests/cases/compiler/thisIndexOnExistingReadonlyFieldIsNotNever.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// @strict: true | ||
declare class Component<P, S = {}> { | ||
readonly props: Readonly<{ children?: unknown }> & Readonly<P>; | ||
state: Readonly<S>; | ||
} | ||
interface CoachMarkAnchorProps<C> { | ||
anchorRef?: (anchor: C) => void; | ||
} | ||
type AnchorType<P> = Component<P>; | ||
|
||
class CoachMarkAnchorDecorator { | ||
decorateComponent<P>(anchor: P) { | ||
return class CoachMarkAnchor extends Component<CoachMarkAnchorProps<AnchorType<P>> & P, {}> { | ||
private _onAnchorRef = (anchor: AnchorType<P>) => { | ||
const anchorRef = this.props.anchorRef; | ||
if (anchorRef) { | ||
anchorRef(anchor); | ||
} | ||
} | ||
}; | ||
} | ||
} |