Skip to content

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

Closed
@xaviergonz

Description

@xaviergonz

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:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions