Skip to content
Merged
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: 5 additions & 8 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18332,6 +18332,11 @@ func (c *Checker) getBaseTypes(t *Type) []*Type {
}
}
}
// In general, base type resolution always precedes member resolution. However, it is possible
// for resolution of type parameter defaults to cause circularity errors, possibly leaving
// members partially resolved. Here we ensure any such partial resolution is reset.
// See https://github.com/microsoft/TypeScript/issues/16861 for an example.
t.objectFlags &^= ObjectFlagsMembersResolved
data.baseTypesResolved = true
}
return data.resolvedBaseTypes
Expand Down Expand Up @@ -18395,14 +18400,6 @@ func (c *Checker) resolveBaseTypesOfClass(t *Type) {
c.error(t.symbol.ValueDeclaration, diagnostics.Type_0_recursively_references_itself_as_a_base_type, c.TypeToString(t))
return
}
// !!! This logic is suspicious. We really shouldn't be un-resolving members after they've been resolved.
// if t.resolvedBaseTypes == resolvingEmptyArray {
// // Circular reference, likely through instantiation of default parameters
// // (otherwise there'd be an error from hasBaseType) - this is fine, but `.members` should be reset
// // as `getIndexedAccessType` via `instantiateType` via `getTypeFromClassOrInterfaceReference` forces a
// // partial instantiation of the members without the base types fully resolved
// t.members = nil
// }
t.AsInterfaceType().resolvedBaseTypes = []*Type{reducedBaseType}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
circularConstraintYieldsAppropriateError.ts(10,7): error TS2310: Type 'Foo' recursively references itself as a base type.
circularConstraintYieldsAppropriateError.ts(17,5): error TS2339: Property 'bar' does not exist on type 'Foo'.


==== circularConstraintYieldsAppropriateError.ts (2 errors) ====
==== circularConstraintYieldsAppropriateError.ts (1 errors) ====
// https://github.com/Microsoft/TypeScript/issues/16861
class BaseType<T> {
bar: T
Expand All @@ -21,6 +20,4 @@ circularConstraintYieldsAppropriateError.ts(17,5): error TS2339: Property 'bar'
}

const foo = new Foo();
foo.bar.test
~~~
!!! error TS2339: Property 'bar' does not exist on type 'Foo'.
foo.bar.test

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,9 @@ const foo = new Foo();
>Foo : Symbol(Foo, Decl(circularConstraintYieldsAppropriateError.ts, 7, 1))

foo.bar.test
>foo.bar.test : Symbol(test, Decl(circularConstraintYieldsAppropriateError.ts, 10, 15))
>foo.bar : Symbol(BaseType.bar, Decl(circularConstraintYieldsAppropriateError.ts, 1, 19))
>foo : Symbol(foo, Decl(circularConstraintYieldsAppropriateError.ts, 15, 5))
>bar : Symbol(BaseType.bar, Decl(circularConstraintYieldsAppropriateError.ts, 1, 19))
>test : Symbol(test, Decl(circularConstraintYieldsAppropriateError.ts, 10, 15))

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ const foo = new Foo();
>Foo : typeof Foo

foo.bar.test
>foo.bar.test : any
>foo.bar : any
>foo.bar.test : true
>foo.bar : { test: true; }
>foo : Foo
>bar : any
>test : any
>bar : { test: true; }
>test : true

This file was deleted.