Skip to content
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

[Question] Other object's properties eq to {[key:string]: string} in TypeScript #1692

Open
moshfeu opened this issue Sep 15, 2019 · 0 comments

Comments

@moshfeu
Copy link

moshfeu commented Sep 15, 2019

I wanted to ask what is the equivalent way (if there is one) to declare a type with specific required property and unlimited optional properties as the following typescript code:

interface BaseEntity {
  id: string;
}

interface Entity extends BaseEntity {
  [key: string]: string;
}

For example:

{ id: 'some_id' } // valid
{ id: 'some_id', foo: 'bar' } // valid
{ } // invalid
{ foo: 'bar' } // invalid

Example of how it works in TypeScript

https://www.typescriptlang.org/play/#code/JYOwLgpgTgZghgYwgAgEJwM4QKLmGAT2QG8AoZZYAEwC5kMwpQBzAblIF9TTRJZEUuMPiIQAHpBBUMaTDjyES5ZAG0A1hAJ0GTEMwC62xi3ZdSCAPYgGyOHSEjkAXiUVqdAOQAjADZwPADTKMBYWnl5wUB6c3JbWYMhe9gpELmQUIWHI3pHRHEA

I use it for TypeScript "Type Checking JavaScript Files" and I hope that the solution is also fit in this case.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant