Skip to content

IEntity Indexer is causing 'loose' keyof operator, breaking intellisense & ability to write property constraints #57

@cristian-eriomenco

Description

@cristian-eriomenco

Problem description:

The indexer definition [index: string]: unknown; on the IEntity

export interface IEntity {
    id?: Guid | null;
    logicalName: string;
    [index: string]: unknown;   // indexer here
    formattedValues?: Dictionary<string>;
}

Is stopping usage of strongly type property pickers / intellisense

Minimal Example:

interface Person {
    dateOfBirth: Date;
    [index: string]: unknown; // comment out to get intellisense on line 7
}

const prop1: keyof Person = ""; // when indexer present  => no intellisense
const prop2: keyof Person = ""; // when indexer removed => "dateOfBirth" present 

Playground link

Realistic use case:

export interface IEntity {
    id?: Guid | null;
    logicalName: string;
    [index: string]: unknown;   // indexer here
    formattedValues?: Dictionary<string>;
}

export interface myOrg_Person extends IEntity { 
    myOrg_FirstName: string;
    myOrg_DateOfBirth: string;
}

// any builder, schema definition, entity mapper, predicate function, property whitelisting
const p = create<myOrg_Person>()
  .with("myOrg_FirstName", () => faker.person.firstname()) // intellisense due to with<T>(p: keyof T) {...}
  .with("myOrg_DateOfBirth", () => faker.person.dob()) // intellisense
  .build();

Questions

  1. Is this indexer actually used / needed ?
  2. Can it be done using additionalProps: Map<string, unknown>; or similar container for dynamic properties? or an associated type for holding it?
  3. What is the temporary solution to make keyof T work?

PS: Publisher prefixing sucks big time. Aliasing for prop name mapping or let the consumer take the risk of namespace collision.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions