Skip to content
Open
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
3 changes: 1 addition & 2 deletions packages/typescript/src/enums/objectFlags.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export enum ObjectFlags {
IsClassInstanceClone = 1 << 26,
IdenticalBaseTypeCalculated = 1 << 27,
IdenticalBaseTypeExists = 1 << 28,
UnresolvedMembers = 1 << 29,
FromTypeNode = 1 << 30,
FromTypeNode = 1 << 29,
IsGenericTypeComputed = 1 << 22,
IsGenericObjectType = 1 << 23,
IsGenericIndexType = 1 << 24,
Expand Down
3 changes: 1 addition & 2 deletions packages/typescript/src/enums/objectFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export var ObjectFlags: any;
ObjectFlags[ObjectFlags["IsClassInstanceClone"] = 67108864] = "IsClassInstanceClone";
ObjectFlags[ObjectFlags["IdenticalBaseTypeCalculated"] = 134217728] = "IdenticalBaseTypeCalculated";
ObjectFlags[ObjectFlags["IdenticalBaseTypeExists"] = 268435456] = "IdenticalBaseTypeExists";
ObjectFlags[ObjectFlags["UnresolvedMembers"] = 536870912] = "UnresolvedMembers";
ObjectFlags[ObjectFlags["FromTypeNode"] = 1073741824] = "FromTypeNode";
ObjectFlags[ObjectFlags["FromTypeNode"] = 536870912] = "FromTypeNode";
ObjectFlags[ObjectFlags["IsGenericTypeComputed"] = 4194304] = "IsGenericTypeComputed";
ObjectFlags[ObjectFlags["IsGenericObjectType"] = 8388608] = "IsGenericObjectType";
ObjectFlags[ObjectFlags["IsGenericIndexType"] = 16777216] = "IsGenericIndexType";
Expand Down
1 change: 0 additions & 1 deletion tsc/internal/api/enum_values_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,9 @@ type IterationTypesKey struct {
// PropertiesTypesKey

type PropertiesTypesKey struct {
typeId TypeId
include TypeFlags
includeOrigin bool
unresolvedMembers bool
typeId TypeId
include TypeFlags
includeOrigin bool
}

// NonExistentPropertyKey
Expand Down Expand Up @@ -19461,9 +19460,7 @@ func (c *Checker) resolveObjectTypeMembers(t *Type, source *Type, typeParameters
if !instantiated {
members = maps.Clone(members)
}
c.setStructuredTypeMembers(t, members, callSignatures, constructSignatures, indexInfos)
thisArgument := core.LastOrNil(typeArguments)
t.objectFlags |= ObjectFlagsUnresolvedMembers
for _, baseType := range baseTypes {
instantiatedBaseType := baseType
if thisArgument != nil {
Expand All @@ -19482,7 +19479,6 @@ func (c *Checker) resolveObjectTypeMembers(t *Type, source *Type, typeParameters
return findIndexInfo(indexInfos, info.keyType) == nil
}))
}
t.objectFlags &^= ObjectFlagsUnresolvedMembers
}
c.setStructuredTypeMembers(t, members, callSignatures, constructSignatures, indexInfos)
}
Expand Down Expand Up @@ -27113,7 +27109,7 @@ func (c *Checker) getExtractStringType(t *Type) *Type {
}

func (c *Checker) getLiteralTypeFromProperties(t *Type, include TypeFlags, includeOrigin bool) *Type {
key := PropertiesTypesKey{typeId: t.id, include: include, includeOrigin: includeOrigin, unresolvedMembers: t.objectFlags&ObjectFlagsUnresolvedMembers != 0}
key := PropertiesTypesKey{typeId: t.id, include: include, includeOrigin: includeOrigin}
if cached, ok := c.propertiesTypes[key]; ok {
return cached
}
Expand Down
3 changes: 1 addition & 2 deletions tsc/internal/checker/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,7 @@ const (
// Flags that require TypeFlags.Object and ObjectFlags.Reference
ObjectFlagsIdenticalBaseTypeCalculated = 1 << 27 // has had `getSingleBaseForNonAugmentingSubtype` invoked on it already
ObjectFlagsIdenticalBaseTypeExists = 1 << 28 // has a defined cachedEquivalentBaseType member
ObjectFlagsUnresolvedMembers = 1 << 29 // Member resolution in process
ObjectFlagsFromTypeNode = 1 << 30 // Originates in resolution of AST type node
ObjectFlagsFromTypeNode = 1 << 29 // Originates in resolution of AST type node
// Flags that require TypeFlags.UnionOrIntersection or TypeFlags.Substitution
ObjectFlagsIsGenericTypeComputed = 1 << 22 // IsGenericObjectType flag has been computed
ObjectFlagsIsGenericObjectType = 1 << 23 // Union or intersection contains generic object type
Expand Down
61 changes: 61 additions & 0 deletions tsc/internal/fourslash/tests/noGhostErrors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package fourslash_test

import (
"testing"

"github.com/microsoft/TypeScript/tsc/internal/fourslash"
"github.com/microsoft/TypeScript/tsc/internal/testutil"
)

func TestNoGhostErrors(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `
interface ZodType<T> {
optional: "true" | "false";
output: T;
}

interface ZodString extends ZodType<string> {
optional: "false";
}

type ZodShape = Record<string, any>;
type Prettify<T> = { [K in keyof T]: T[K] } & {};
type InferObjectType<Shape extends ZodShape> = Prettify<
{
[k in keyof Shape as Shape[k] extends { optional: "true" }
? k
: never]?: Shape[k]["output"];
} & {
[k in keyof Shape as Shape[k] extends { optional: "true" }
? never
: k]: Shape[k]["output"];
}
>;
interface ZodObject<T extends ZodShape> extends ZodType<InferObjectType<T>> {
optional: "false";
}

interface ZodOptional<T extends ZodType<any>>
extends ZodType<T["output"] | undefined> {
optional: "true";
}

declare function object<T extends ZodShape>(shape: T): ZodObject<T>;
declare function string(): ZodString;
declare function optional<T extends ZodType<any>>(schema: T): ZodOptional<T>;

const Category = object({
name: string(),
get parent/*1*/() {
return optional(Category);
},
});

export const output = Category.output;`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyQuickInfoAt(t, "1", "(accessor) parent: ZodOptional<ZodObject<{\n name: ZodString;\n readonly parent: ZodOptional<ZodObject<...>>;\n}>>", "")
f.VerifyDiagnostics(t, nil)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
keyofGenericExtendingClassDoubleLayer.ts(2,12): error TS2564: Property 'createdAt' has no initializer and is not definitely assigned in the constructor.
keyofGenericExtendingClassDoubleLayer.ts(9,7): error TS2589: Type instantiation is excessively deep and possibly infinite.
keyofGenericExtendingClassDoubleLayer.ts(10,12): error TS2564: Property 'age' has no initializer and is not definitely assigned in the constructor.


==== keyofGenericExtendingClassDoubleLayer.ts (2 errors) ====
==== keyofGenericExtendingClassDoubleLayer.ts (3 errors) ====
class Model<Attributes = any> {
public createdAt: Date;
~~~~~~~~~
Expand All @@ -14,6 +15,8 @@ keyofGenericExtendingClassDoubleLayer.ts(10,12): error TS2564: Property 'age' ha
class AutoModel<T> extends Model<ModelAttributes<T>> {}

class PersonModel extends AutoModel<PersonModel> {
~~~~~~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
public age: number;
~~~
!!! error TS2564: Property 'age' has no initializer and is not definitely assigned in the constructor.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
mutuallyRecursiveInference.ts(2,5): error TS2564: Property 'a' has no initializer and is not definitely assigned in the constructor.
mutuallyRecursiveInference.ts(9,5): error TS2564: Property 'a' has no initializer and is not definitely assigned in the constructor.
mutuallyRecursiveInference.ts(10,5): error TS2564: Property 'b' has no initializer and is not definitely assigned in the constructor.
mutuallyRecursiveInference.ts(12,9): error TS2589: Type instantiation is excessively deep and possibly infinite.


==== mutuallyRecursiveInference.ts (3 errors) ====
==== mutuallyRecursiveInference.ts (4 errors) ====
class T<A> {
a: A;
~
Expand All @@ -22,6 +23,8 @@ mutuallyRecursiveInference.ts(10,5): error TS2564: Property 'b' has no initializ
!!! error TS2564: Property 'b' has no initializer and is not definitely assigned in the constructor.
m2() {
this.a
~~~~~~
!!! error TS2589: Type instantiation is excessively deep and possibly infinite.
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ const Activity = z.object({
},
});
export type ActivityT = output<typeof Activity>;
>ActivityT : { name: string; subactivities: unknown; }
>ActivityT : { name: string; subactivities: { name: string; subactivities: any[] | null; }[] | null; }
>Activity : $ZodObject<{ name: $ZodString; readonly subactivities: $ZodNullable<$ZodArray<$ZodObject<any>>>; }>

// (4) reference through a separately-declared const
Expand Down Expand Up @@ -355,6 +355,6 @@ const NodeArray = z.array(Node1);
>Node1 : $ZodObject<{ name: $ZodString; readonly children: $ZodOptional<$ZodArray<$ZodObject<any>>>; }>

export type Node1T = output<typeof Node1>;
>Node1T : { name: string; children?: unknown; }
>Node1T : { name: string; children?: { name: string; children?: any[] | undefined; }[] | undefined; }
>Node1 : $ZodObject<{ name: $ZodString; readonly children: $ZodOptional<$ZodArray<$ZodObject<any>>>; }>

Loading