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.

Type safety support for properties which has (string & {}) definition

See original GitHub issue

Hi 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:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
freniccommented, Jan 20, 2022

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.

1reaction
freniccommented, Jan 20, 2022

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 why string & {} is generated.

Read more comments on GitHub >

github_iconTop 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 >

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