Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Circular record cannot be assigned an empty record #34690

Copy link
Copy link
@niedzielski

Description

@niedzielski
Issue body actions

TypeScript Version: 3.7.0-beta

Search Terms: recursive empty record

Code

const foo: Record<never, never> = {} // OK

interface RecordOfRecords extends Record<keyof any, RecordOfRecords> {}
const recordOfRecords: RecordOfRecords = {}
recordOfRecords.propA = {...(foo !== undefined ? {foo} : {})} // OK
recordOfRecords.propB = {...(foo && {foo})} // OK
recordOfRecords.propC = {...(foo !== undefined && {foo})} // Not OK
// ^Error:
//  Type '{} | { foo: Record<never, never>; }' is not assignable to type 'RecordOfRecords'.
//    Type '{}' is not assignable to type 'RecordOfRecords'.
//      Index signature is missing in type '{}'.(2322)

interface RecordOfRecordsOrEmpty extends Record<keyof any, RecordOfRecordsOrEmpty | {}> {}
const recordsOfRecordsOrEmpty: RecordOfRecordsOrEmpty = {}
recordsOfRecordsOrEmpty.propA = {...(foo !== undefined ? {foo} : {})} // OK
recordsOfRecordsOrEmpty.propB = {...(foo && {foo})} // OK
recordsOfRecordsOrEmpty.propC = {...(foo !== undefined && {foo})} // OK

Expected behavior: Empty objects are always assignable to Records.

Actual behavior: Empty objects are only assignable to the non-recursive records.

Playground Link

Related Issues: #25437

Edit: sorry, but I couldn't find this issue in the tracker although I'm almost certain it must exist. If possible, please link this to any existing (possibly closed) issue.

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptA bug in TypeScript

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.