Skip to content

Create type for autocapitalize propertie of input and textarea #21464

Closed
rangzen wants to merge 1 commit intoionic-team:mainfrom
rangzen:autocapitalize-type
Closed

Create type for autocapitalize propertie of input and textarea #21464
rangzen wants to merge 1 commit intoionic-team:mainfrom
rangzen:autocapitalize-type

Conversation

@rangzen
Copy link
Copy Markdown

@rangzen rangzen commented Jun 9, 2020

Fix #21463

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: #21463

What is the new behavior?

  • Add a type

Does this introduce a breaking change?

  • Yes
  • No

Probably not cause everybody use 'on' and 'off' already and browser compatibility is poor right now so probably few people use it.

Other information

@ionitron-bot ionitron-bot bot added the package: core @ionic/core package label Jun 9, 2020
Copy link
Copy Markdown
Contributor

@liamdebeasi liamdebeasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! There are a few things that we will need to correct before this gets merged in:

  1. autocapitalize accepts more values than just "on" or "off": https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autocapitalize. The following strings are accepted: on, off, none, sentences, words, characters.

  2. The build is failing. When you make your changes you need to run npm run lint.fix and npm run build from the core directory.

  3. The ion-textarea component also has an autocapitalize property, so we should make these changes there as well: https://github.com/ionic-team/ionic/blob/master/core/src/components/textarea/textarea.tsx#L40

When you update the types, you should add it as an AutocapitalizeTypes type in interface.d.ts. See https://github.com/ionic-team/ionic/blob/4fd7c0cc5a6c97100fa380e4ff1be0bb84c7006b/core/src/interface.d.ts#L40 as an example.

So you would do something like:

export type AutocapitalizeTypes = 'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters';

@rangzen rangzen marked this pull request as draft June 9, 2020 14:21
Fix ionic-team#21463.
Change none to off in textarea for coherence.
Didn't use parenthese like in AutocompleteTypes.
@rangzen rangzen force-pushed the autocapitalize-type branch from f4b28f3 to 1e2eb9d Compare June 9, 2020 14:25
@rangzen rangzen changed the title Change type of autocapitalize propertie of ion-input Create type for autocapitalize propertie of input and textarea Jun 9, 2020
@rangzen
Copy link
Copy Markdown
Author

rangzen commented Jun 9, 2020

[ ERROR ]  TypeScript: ./src/components.d.ts:2837:15
           Interface 'HTMLIonInputElement' cannot simultaneously extend types
           'IonInput' and 'HTMLStencilElement'.Named property 'autocapitalize'
           of types 'IonInput' and 'HTMLStencilElement' are not identical.
   L2836:  };
   L2837:  interface HTMLIonInputElement extends Components.IonInput, HTMLStencilElement {
   L2838:  }
[ ERROR ]  TypeScript: ./src/components.d.ts:3149:15
           Interface 'HTMLIonTextareaElement' cannot simultaneously extend
           types 'IonTextarea' and 'HTMLStencilElement'.Named property
           'autocapitalize' of types 'IonTextarea' and 'HTMLStencilElement' are
           not identical.
   L3148:  };
   L3149:  interface HTMLIonTextareaElement extends Components.IonTextarea, HTMLStencilElement {
   L3150:  }

https://github.com/ionic-team/ionic/blob/master/core/src/components.d.ts#L2837 implements two interfaces and it seems that there is a conflict with the internal definitions of the DOM in Typescript

/node_modules/typescript/lib/lib.dom.d.ts

interface HTMLElement extends Element, DocumentAndElementEventHandlers, ElementCSSInlineStyle, ElementContentEditable, GlobalEventHandlers, HTMLOrSVGElement {
[...]
    autocapitalize: string;

Any idea about dealing with that?

@rangzen rangzen requested a review from liamdebeasi June 9, 2020 15:02
@liamdebeasi
Copy link
Copy Markdown
Contributor

There need to be some changes in Stencil in order to account for this, so I will make sure that gets merged first.

@liamdebeasi liamdebeasi removed their request for review March 18, 2022 13:27
rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Oct 7, 2022
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
@liamdebeasi
Copy link
Copy Markdown
Contributor

liamdebeasi commented Oct 10, 2022

Thanks for the PR, and apologies for the delay. We appreciate the work you put into creating this PR. However, we are unable to accept the PR at this time. While the experience here is not ideal, the autocapitalize property is working as intended.

The underlying problem is with how TypeScript types the autocapitalize property: https://github.com/microsoft/TypeScript/blob/9c87ded2b3fc4ba4a9a7656e9be39d5e404e6ab6/lib/lib.dom.d.ts#L6360

As shown in the link, the autocapitalize property is of type string in TypeScript's codebase. This means that any type narrowing we do is going to cause a TypeScript error. In this case 'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters' is narrower than the expected string type which is why you got the errors in #21464 (comment).

If TypeScript narrows their types, we will be more than happy to reconsider adding this change to Ionic's codebase. I am going to close this, but let me know if you have any questions. Thank you!

@rangzen
Copy link
Copy Markdown
Author

rangzen commented Oct 11, 2022

Whooo almost 2 years and half :) Thank you for the answer and the links to TypeScript DOM 👍

rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Dec 2, 2022
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Dec 5, 2022
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Jan 23, 2023
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Jan 24, 2023
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Jan 24, 2023
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Jan 24, 2023
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Jan 24, 2023
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Jan 24, 2023
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Jan 24, 2023
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Jan 24, 2023
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Jan 24, 2023
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Jan 24, 2023
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Jan 24, 2023
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
rwaskiewicz pushed a commit to stenciljs/core that referenced this pull request Jan 25, 2023
In #2509, we changed these types to `any` as suggested by Manu. This was done to fix ionic-team/ionic-framework#21464.

Upon further investigation we found that this fix was not correct. The Framework issue had nothing to do with the types on `HTMLStencilElement` and instead were related to the types on `HTMLElement`.

It's worth noting we didn't got the route of specifying the allowed strings further to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'` to align with `lib.dom.d.ts` that's shipped with TypeScript, which just types this property as `string` (on `HTMLElement`). Had we done that, we could/would have run into issues where `string` isn't assignable to `'off' | 'on' | 'none' | 'sentences' | 'words' | 'characters'`, as the former is wider than that latter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: ion-input autocapitalize type should be string literal type

2 participants