Repository navigation
Conversation
Add a types.ts file. Though doesn't convert index.native.js to TS.
SearchControl component to TypeScript
kienstra
commented
Jul 22, 2022
| * Internal dependencies | ||
| */ | ||
| import { Button } from '../'; | ||
| import { Button } from '../button'; |
Contributor
Author
There was a problem hiding this comment.
Without this change, there's an error, probably from Button not being in TypeScript:
File 'plugins/gutenberg/packages/components/src/index.js' is not listed within the file list of project 'plugins/gutenberg/packages/components/tsconfig.json'. Projects must list all files or use an 'include' pattern.
The file is in the program because:
Imported via '../' from file 'plugins/gutenberg/packages/components/src/search-control/index.tsx'
kienstra
commented
Jul 22, 2022
| onClick={ () => { | ||
| onChange( '' ); | ||
| searchRef.current.focus(); | ||
| if ( searchRef.current ) { |
Contributor
Author
There was a problem hiding this comment.
Without this if conditional, there's a TypeScript error:
(property) React.MutableRefObject<undefined>.current: undefined
Conversion of type 'undefined' to type 'HTMLInputElement' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.ts(2352)
Contributor
Author
There was a problem hiding this comment.
Thanks! Removed this conditional in 366b312
kienstra
commented
Jul 22, 2022
| onChange( '' ); | ||
| searchRef.current.focus(); | ||
| if ( searchRef.current ) { | ||
| ( searchRef.current as HTMLInputElement )?.focus(); |
Contributor
Author
There was a problem hiding this comment.
This ref is passed to an <input> below, so searchRef.current should usually be HTMLInputElement
kienstra
marked this pull request as ready for review
July 22, 2022 20:12
…trol/index.tsx Co-authored-by: Manzoor Wani <manzoorwani.jk@gmail.com>
…trol/types.ts Co-authored-by: Manzoor Wani <manzoorwani.jk@gmail.com>
…trol/types.ts Co-authored-by: Manzoor Wani <manzoorwani.jk@gmail.com>
Contributor
Author
|
Closing in favor of #43871, which handles this. I should have followed up on this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Converts the
SearchControlcomponent to TypeScriptWhy?
As part of an effort to convert
@wordpress/componentsto TypeScriptHow?
Mainly by adding types to the
SearchControlcomponentTesting Instructions
SearchControlcomponentScreenshots or screencast