Skip to content

Error not issued when global type is an alias of an object type literalΒ #57564

Open
@rotu

Description

@rotu

πŸ”Ž Search Terms

array, constructor, bracket

πŸ•— Version & Regression Information

  • This is a crash

⏯ Playground Link

https://www.typescriptlang.org/dev/bug-workbench/?noLib=true&target=99&ts=5.5.0-dev.20240227#code/PTAEAEDsHsBkEsBGAuUAXATgVwKYCgQI0BDDAcxzVRwGdIcAPNPPAExwGMAbUnUMrtETEuoAN55QoDtEg00oAIIYMxAJ6oJUqQB4AKqAC8oLJADWMAO6QAfAAoAdE9JkayYpDUBtALoBKVGVVNX0bSW16S1B9IxNzK0gAGnsnBxc3D29-QJV1UPCAXxYpNDUABz4gvL0bWK1tL3hUSCwAW0QcDB9UPXCpLhxIMjQAC2a2joxCvCKCMBFRaAAzdBG+DsEosngANz4AIgAFDGgKjFLQAHIBodHL0HgaUFbHmnghh8h0cr5LsQLLql9sg8ABuUB2LwARkSoAATLCAMz+UA0YhoR5LeC0JS5EItdqdGygsEQ6GwhGgZF+VHozHYp5iUA3YZjUAEyagAok9jcXjSWTyUCkKHNHB7DC+Uki2kYmhYnFMlmjcaEjBcnmcHgYPgyOQKUhw1WTKXgw2y+mK5mDVnGzpclhzVaPVEjaBYLisVYnKIeUCdE7qxBYBTwBSsaC0SCXZiEcBoGgAWkYFQ4aGTKmgU3BkJ8wqeHM6vhpaLlCqe8gw7zIUrwKazCiZBSAA

πŸ’» Code

// @noLib: true
// @target: esnext

declare global {
  const Array: {
    <T = unknown>(...args:any[]): Array<T>
    new <T = unknown,>(...args:any[]): Array<T>
  }

  type Array<T> = {
    [i: number]: T
    length: number
  }
}

// all of the below give "Property 'length' is missing in type '{}'...":
; ([1, 2, 3]) satisfies Array<number>;
; ([1, 2, 3]) satisfies { length: number };
declare const ar1: never[]
; ar1 satisfies { length: number };
declare const ar2: number[]
; ar2 satisfies { length: number }


// this should throw an error but it doesn't
// @ts-expect-error
; ([] as number[]) satisfies string[]

export { }

πŸ™ Actual behavior

Types created with the T[] and objects created with the [x as T] syntax are not typed as Array<T> but instead as {}.

πŸ™‚ Expected behavior

I expect either:

  • T[] syntax and Array<T> to be completely synonymous
  • A compiler error that the Array type is not an instantiable type

Additional information about the issue

Related to #57009.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-repros

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions