Skip to content

extends keyof does not allow extended new keys on interfaces since 4.3.0Β #44295

Closed
@posva

Description

@posva

Bug Report

πŸ”Ž Search Terms

  • extends keyof, missing key

πŸ•— Version & Regression Information

I saw this in 4.3.0 beta, it seems to exists in the nightly. It was working on 4.2.x

⏯ Playground Link

export interface GlobalOptions {
  // cannot be added or it wouldn't be able to be extended
  // suffix: string
}

// this is added by a user to extend a global customization
export interface GlobalOptions {
   // suffix: 'New'
}

export type WithSuffix<S extends string> = `${S}${'suffix' extends keyof GlobalOptions ? GlobalOptions['suffix'] : 'Suffix'}`

declare let a: WithSuffix<'hi'>
Output
export {};
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "ES2017",
    "jsx": "react",
    "module": "ESNext",
    "moduleResolution": "node"
  }
}

Playground Link: Provided


### πŸ™ Actual behavior

Error with `suffix cannot be used to index`

### πŸ™‚ Expected behavior

No Error

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions