Type safety support for properties which has (string & {}) definition
See original GitHub issueHi there,
I use a library typestyle
which depends on csstype
. And I have a next case:
import {style} from 'typestyle';
export const styles = {
header: style({
// There are IDE hints, but I'm still able to put any value
display: 'flexxxxx',
})
};
It happens because the definition of display
looks like:
export type Display =
| Globals
| DataType.DisplayOutside
| DataType.DisplayInside
| DataType.DisplayInternal
| DataType.DisplayLegacy
| "contents"
| "list-item"
| "none"
| (string & {});
I understand the definition relies on web specifications and that’s absolutely correct. But it doesn’t make sense from a type safety perspective.
Is it possible to solve the issue? Maybe csstype
could do two kind of builds - default
and type safe
?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Typescript: How to add type safety to object properties?
Record<CommandTypes, string> will give you a object who's keys are the distributed union of CommandType and the values have to be strings.
Read more >Type safety - Wikipedia
In computer science, type safety and type soundness are the extent to which a programming language discourages or prevents type errors. Type safety...
Read more >Documentation - Advanced Types - TypeScript
A type guard is some expression that performs a runtime check that guarantees the type in some scope. Using type predicates. To define...
Read more >Creating type-safe properties with ECMAScript 6 proxies
The idea behind type safety is that each variable or property can only contain a particular type of value. In type-safe languages, the...
Read more >Strategic Scala Style: Practical Type Safety
While Scala is has a compiler that can help you catch errors, and many call it "type-safe", there is in fact a whole...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s pretty intense to generate a union for every possible combination for every property of this kind. That’s why literal template types will come in handy.
As soon as I have time to fix it. Soon I hope.
That’s not true. The
display
property accepts a two-value syntax even though it’s rarely used. That’s whystring & {}
is generated.