Skip to content

Crash when using TS 4.1.2 with useDefineForClassFields and key union #41798

New issue

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

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

Already on GitHub? Sign in to your account

Closed
xaviergonz opened this issue Dec 3, 2020 · 0 comments · Fixed by #43055
Closed

Crash when using TS 4.1.2 with useDefineForClassFields and key union #41798

xaviergonz opened this issue Dec 3, 2020 · 0 comments · Fixed by #43055
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@xaviergonz
Copy link

xaviergonz commented Dec 3, 2020

TypeScript Version: 4.1.2

Search Terms: key union, useDefineForClassFields

Code

Given useDefineForClassFields is set to true

type M<MP extends { [k: string]: {} }> = {
  [k in keyof MP & string]: any // if & string is ommited then it compiles ok
}

function F<D extends { [k: string]: {} }>(
  _d: D
): {
  new (): M<D>
} {
  return null as any
}

class P extends F({ x: {} }) {}

Expected behavior:

It should compile without crashing

Actual behavior:

TypeError: Cannot read property 'length' of undefined

      at Object.find (../../node_modules/typescript/lib/typescript.js:509:35)
      at checkKindsOfPropertyMemberOverrides (../../node_modules/typescript/lib/typescript.js:75911:52)
      at checkClassLikeDeclaration (../../node_modules/typescript/lib/typescript.js:75736:21)
      at checkClassDeclaration (../../node_modules/typescript/lib/typescript.js:75662:13)
      at checkSourceElementWorker (../../node_modules/typescript/lib/typescript.js:77032:28)
      at checkSourceElement (../../node_modules/typescript/lib/typescript.js:76873:17)
      at Object.forEach (../../node_modules/typescript/lib/typescript.js:382:30)
      at checkSourceFileWorker (../../node_modules/typescript/lib/typescript.js:77217:20)
      at checkSourceFile (../../node_modules/typescript/lib/typescript.js:77184:13)
      at getDiagnosticsWorker (../../node_modules/typescript/lib/typescript.js:77273:17)

Playground Link:

See the crash in the browser console

https://www.typescriptlang.org/play?useDefineForClassFields=true#code/C4TwDgpgBAsgPDAClCAPYEB2ATAzlAbygG0BrALil2ACcBLTAcwF1KCBfKdgPigF5CAWABQUEqSgMopCCAD2AM1jIAZFVoMWlAIaYQUAPQHJStdXpNJ+OQFsbdDNijAAFlknAoAY1tg6AGwhrUhF2EREFAFdML2A6OUwoADE4ABEUdCw8QnFKc01WQk4eAAoRMQB9bEpUkQBKNnKoTAgAdygShtg07lChUSgaCGBImkTMSP9-KG18XRBQ8OEvf1n8ZDQMHHwkkqJUNmK6oqA

Related Issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants