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.

TypeScript types taken as literals

See original GitHub issue

Type definitions are a little weird. I’m having TS get angry with Animated Values. When I pass a number as a Value, it takes it as a literal. Current workaround is to pass a number with <number> to force the type. Otherwise, it will take my 0 or whatever else I pass it as the type, literally.

screen shot 2019-02-25 at 1 50 34 pm screen shot 2019-02-25 at 2 00 31 pm

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
satya164commented, Jun 12, 2020

Very weird. I have always passed the type parameter so never seen this issue.

Changing the definitions to something like this seems to work:

class AnimatedValue<T extends Value> extends AnimatedNode<T> {
  constructor(value?: T);

  setValue(
    value: Adaptable<
      T extends number
        ? number
        : T extends string
        ? string
        : T extends boolean
        ? boolean
        : T
    >
  ): void;
}

NOTE: probably should be done in the Adaptable class instead of here.

Looks super ugly though.

0reactions
jakub-gonetcommented, Nov 22, 2019

Hey, I’m sorry for the late response 😔

I think this issue may be outdated now, so I’m closing it.

If you still face the same problem feel free to reopen

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Template Literal Types - TypeScript
Template literal types build on string literal types, and have the ability to expand into many strings via unions. They have the same...
Read more >
What are string literal types in TypeScript ? - GeeksforGeeks
String literal types work well with union types and type aliases in practice. These properties can be combined to give strings enum-like ...
Read more >
TypeScript: Template Literal Types - Michal Zalecki
Literal types in TypeScript allow for narrowing down the type to the exact value. You can communicate in the type system that the...
Read more >
String Literal Types in TypeScript - Marius Schulz
With TypeScript 1.8, string literal types made their way into the language. The pull request in which they're implemented summarizes them as ...
Read more >
TypeScript String Literal Types
A TypeScript string literal type defines a type that accepts specified string literal. · Use the string literal types with union types and...
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