v2 [TypeScript] More accurate typings
See original GitHub issueWhile 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:
- Created 5 years ago
- Reactions:1
- Comments:13 (6 by maintainers)
Top 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 >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
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.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
:The type should probably be: