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.

v2 [TypeScript] More accurate typings

See original GitHub issue

While playing around with v2 and TypeScript, I ran into the following problem:

import { TextInput } from 'grommet';

type Handler = React.KeyboardEventHandler<HTMLInputElement>;
const handler: Handler = ({key}) => console.log(key); 
const Input = () => <TextInput onKeyUp={handler} /> // <-- TypeScript complains here

The problem is that the onKeyUp property is not included in the typings. Looking at the code, if not for the typings, I believe this would actually work as intended: TextInput.js#L338.

This is definitely a broader problem: the typings should extend the typings for the appropriate html element, in this case probably input. That would take care of all the attributes you assume you should be able to set for e.g. TextInput.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
hc-12commented, Nov 3, 2018

I too have stumbled into this problem when using TextInput.

The fix for this particular case, I just need to extend or intersect with IntrinsicElements['input']. This would need to be done for the rest of the components that grommet extends from.

declare const TextInput: React.ComponentType<TextInputProps & JSX.IntrinsicElements['input']>;
2reactions
hc-12commented, Nov 3, 2018

This is somewhat related, not sure whether i should open a new issue. There’s an incorrect type for props that accepts string value and boolean. At the moment they all accept string as value which is incorrect and will get console warning.

For example in Box.flex & Box.fill:

flex?: "grow" | "shrink" | "true" | "false";
fill?: "horizontal" | "vertical" | "true" | "false";

The type should probably be:

flex?: "grow" | "shrink" | boolean;
fill?: "horizontal" | "vertical" | boolean;
Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - TypeScript 2.0
With TypeScript 2.0, the type checker analyses all possible flows of control in statements and expressions to produce the most specific type possible...
Read more >
Documentation - Everyday Types - TypeScript
In this chapter, we'll cover some of the most common types of values you'll find in JavaScript code, and explain the corresponding ways...
Read more >
TypeScript: JavaScript With Syntax For Types.
TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale. Try TypeScript Now. Online or...
Read more >
Documentation - Conditional Types - TypeScript
Conditional Types. At the heart of most useful programs, we have to make decisions based on input. JavaScript programs are no different, but...
Read more >
Documentation - The Basics - TypeScript
JavaScript only truly provides dynamic typing - running the code to see ... in the long run, and enables more thorough checks 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