Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17727,6 +17727,19 @@ func (c *Checker) getConstraintOfIndexedAccess(t *Type) *Type {
}

func (c *Checker) getConstraintFromIndexedAccess(t *Type) *Type {
d := t.AsIndexedAccessType()
if d.resolvedConstraint == nil {
// The constraint is cached because it can be expensive to compute (e.g. when the index type is constrained
// to a large union) and type relations may request it many times, such as once per constituent of a target union.
d.resolvedConstraint = core.OrElse(c.computeConstraintFromIndexedAccess(t), c.noConstraintType)
}
if d.resolvedConstraint != c.noConstraintType {
return d.resolvedConstraint
}
return nil
}

func (c *Checker) computeConstraintFromIndexedAccess(t *Type) *Type {
d := t.AsIndexedAccessType()
if c.isMappedTypeGenericIndexedAccess(t) {
// For indexed access types of the form { [P in K]: E }[X], where K is non-generic and X is generic,
Expand Down
7 changes: 4 additions & 3 deletions tsc/internal/checker/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1539,9 +1539,10 @@ func (t *IndexType) Target() *Type { return t.target }

type IndexedAccessType struct {
ConstrainedType
objectType *Type
indexType *Type
accessFlags AccessFlags // Only includes AccessFlags.Persistent
objectType *Type
indexType *Type
accessFlags AccessFlags // Only includes AccessFlags.Persistent
resolvedConstraint *Type
}

func (t *IndexedAccessType) ObjectType() *Type { return t.objectType }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// @strict: true
// @noEmit: true
// @noTypesAndSymbols: true

// https://github.com/microsoft/TypeScript/issues/65654

type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
type Table = `t${Digit}${Digit}`; // 100 tables
type TableColumn<T extends Table> = "id" | "name" | `${T}_c${Digit}`; // 12 columns per table

type ColumnMap = { [T in Table]: TableColumn<T> };
interface Columns extends ColumnMap {}
type Column = TableColumn<Table>;
type ColumnFor<T extends Table> = Columns[T];

declare function parent<C extends Column | undefined>(column?: C): C;

export function parentOf<T extends Table>(column: ColumnFor<T>) {
return parent(column);
}
Loading