question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow optional property syntax, similar to typescript with key?: value

See original GitHub issue

It would be great for users coming from typescript to be able to write the following:

type ObjectType = {
  key?: string
}

const test: ObjectType = {};

Thanks.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
thecotnecommented, Jun 22, 2021

Object.keys and Object.entries also give different results when prop is not there vs when prop is undefined

Screenshot 2021-06-22 at 18 52 56
0reactions
JSMonkcommented, Jun 22, 2021

It’s true. And also we infer the keys result from the object type.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Deal with Optional Things and "Undefined" in TypeScript
First, if you don't tell TypeScript that a property is optional, it will expect it to be set. Adding ? to the property...
Read more >
Documentation - Advanced Types - TypeScript
This page lists some of the more advanced ways in which you can model types, it works in tandem with the Utility Types...
Read more >
Optional property class in typescript - Stack Overflow
When someone will use your interface IEmployee then middleName will be optional but firstName and lastName is compulsory. let emp: IEmployee = { ......
Read more >
How to Make Certain Properties Optional in TypeScript
In the above example, the pet is an optional property. It's useful, but every time you would like to perform some operations on...
Read more >
Interfaces with Optional Properties - TypeScript - LogicBig
In TypeScript, the interfaces which describe objects can have optional properties. Interfaces with optional properties are written similar ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found