Skip to content

Crash when defining Array type via [] syntax #57009

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
rotu opened this issue Jan 10, 2024 · 5 comments
Open

Crash when defining Array type via [] syntax #57009

rotu opened this issue Jan 10, 2024 · 5 comments
Labels
Bug A bug in TypeScript Has Repro This issue has compiler-backed repros: https://aka.ms/ts-repros Help Wanted You can do this
Milestone

Comments

@rotu
Copy link

rotu commented Jan 10, 2024

πŸ”Ž Search Terms

Array type define crash

πŸ•— Version & Regression Information

  • This is a crash

⏯ Playground Link

https://www.typescriptlang.org/dev/bug-workbench/?noLib=true#code/PTAEAEDsHsBkEsBGAuUAXATgVwKYCg0BPABx1AEEMMBDQgHgBUA+UAXlAYG0BdAbjyA

πŸ’» Code

// @noLib: true
type Array<T> = T[];

πŸ™ Actual behavior

Typescript crashes:

createDeferredTypeReference@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:52280:42
getTypeFromArrayOrTupleTypeNode@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:52908:93
getTypeFromTypeNodeWorker@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:54875:20
getTypeFromTypeNode@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:54828:45
getDeclaredTypeOfTypeAlias@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:49869:33
tryGetDeclaredTypeOfSymbol@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:49955:18
getDeclaredTypeOfSymbol@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:49948:16
getTypeOfGlobalSymbol@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:52644:45
getGlobalType@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:52678:42
initializeTypeChecker@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:75719:27
createTypeChecker@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:42674:7
getTypeChecker@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:101959:46
synchronizeHostDataWorker@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:121935:17
synchronizeHostData@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:121830:11
getProgram@https://typescript.azureedge.net/cdn/5.4.0-dev.20240110/monaco/dev/vs/language/typescript/tsWorker.js:121997:9
updateFile@https://www.typescriptlang.org/17821066377c4486a980330106160c805ea5b4a9-5466acbcf54af90f679c.js:1:25348
G@https://www.typescriptlang.org/17821066377c4486a980330106160c805ea5b4a9-5466acbcf54af90f679c.js:1:17599
F@https://www.typescriptlang.org/17821066377c4486a980330106160c805ea5b4a9-5466acbcf54af90f679c.js:1:17638
A@https://www.typescriptlang.org/component---src-pages-dev-bug-workbench-tsx-6a9bdea3e00be7d97087.js:1:40663
9796/M/

πŸ™‚ Expected behavior

I expect an error message.

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Jan 10, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jan 10, 2024
@RyanCavanaugh
Copy link
Member

Just to be clear, this isn't going to work

@rotu
Copy link
Author

rotu commented Jan 11, 2024

Just to be clear, this isn't going to work

lol, I know. I reduced the repro example from something like type Array<T> = T[] & { push: (t: T) => number } (which is also wrong)

I expect this code to give an error about a circular type reference as if I had written type Array<T> = Array<T>

@rotu
Copy link
Author

rotu commented Jan 11, 2024

It seems there's an internal failure that happens before this crash. It's not my particular definition of the Array type that's a problem but using a type alias to define Array at all:

// @noLib: true

// okay with this definition of Array:
// interface Array<T> {
//   [i:number]:T
// }

// okay with this definition of Array, too:
// class Array<T> {
//   [i:number]:T
// }

// With this definition, things fail and number[] is not the same type as Array<T> anymore:
type Array<T> = {
  [i:number]:T
}

[1,2,3] satisfies {[i:number]:any}

declare const x:number[]
//            ^?
x satisfies Array<number>

Workbench Repro

@typescript-bot typescript-bot added the Has Repro This issue has compiler-backed repros: https://aka.ms/ts-repros label Jan 11, 2024
@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 15, 2024

πŸ‘‹ Hi, I'm the Repro bot. I can help narrow down and track compiler bugs across releases! This comment reflects the current state of this repro running against the nightly TypeScript.


Comment by @rotu

❌ Failed: -

  • Type '{}' does not satisfy the expected type '{ [i: number]: any; }'. Index signature for type 'number' is missing in type '{}'.
  • Type '{}' does not satisfy the expected type 'Array'. Index signature for type 'number' is missing in type '{}'.

Historical Information
Version Reproduction Outputs
4.9.3, 5.0.2, 5.1.3, 5.2.2, 5.3.2

❌ Failed: -

  • Type '{}' does not satisfy the expected type '{ [i: number]: any; }'. Index signature for type 'number' is missing in type '{}'.
  • Type '{}' does not satisfy the expected type 'Array'. Index signature for type 'number' is missing in type '{}'.

@rotu
Copy link
Author

rotu commented Feb 27, 2024

It seems there's an internal failure that happens before this crash. It's not my particular definition of the Array type that's a problem but using a type alias to define Array at all

moved this to standalone issue #57564

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug A bug in TypeScript Has Repro This issue has compiler-backed repros: https://aka.ms/ts-repros Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants