← 输入框|github.com|刷新
Skip to content

Incorrect @Input size typing when strictTemplates is enabled #220

Closed

Description

@KeithGillette

Describe the bug
AOT compilation build under Angular 9 with angularCompilerOptions.strictTemplates: true in tsconfig.app.json generates a error TS2322: Type 'string' is not assignable to type 'number' when binding <as-split-area [size]="'*'">, as the @Input size is typed as number | null in the source code, though the documentation clearly states it can also be bound to '*' in pixel mode.

Activity

  1. Maximaximum commented on Apr 29, 2020

    @Maximaximum

    I'm having exactly the same issue. This is clearly a bug, so I hope it will be fixed

  2. Maximaximum commented on Jun 5, 2020

    @Maximaximum

    Hm, I wonder if this project is still maintained? 😢

  3. literalpie commented on Jun 18, 2020

    @literalpie

    As a workaround, you can use $any in the template

    	<as-split-area [size]="$any('*')">hello</as-split-area>
    
  4. added this to the v6 milestone on Jul 23, 2020
  5. arthur-clifford commented on Aug 22, 2020

    @arthur-clifford

    I was running into an issue with the size not being settable as a string due to typescript checking when using setVisibleAreaSizes
    because I was using a string that included a calc( ... ) value.
    The error I got was:
    this.upperSplit.setVisibleAreaSizes([size1, size2, size3]);
    ~~~~~

    node_modules/angular-split/lib/interface.d.ts:40:18
    40 export interface IOutputAreaSizes extends Array<number | '*'> {

    Note: size2 was a string.

    Being a very naughty programmer I altered the interface defined in angular-split/lib/interface.d.ts so that it read:
    export interface IOutputAreaSizes extends Array<number | string | '*'> {

    That solved my issue with no known other side effects, other than having to make that tweak any time I update.

    I imagine this is causing the size property not accepting a string in strict mode as well.

    I'd like to more formally request that the interface be updated to include string as a type unless there is a good a really good reason not to.

  6. ahnpnl commented on Oct 28, 2020

    @ahnpnl

    Hi, any updates on this issue ?

  7. beeman commented on Oct 28, 2020

    @beeman
    Contributor

    Hi, any updates on this issue ?

    For now the recommend way to handle this is using $any() as mentioned here.

    Once v5 is released, built using Angular 10, I will consider fixing this in v6.

  8. KeithGillette commented on Oct 28, 2020

    @KeithGillette
    Author

    @beeman — Wasn't this incorrect typing already resolved in your ngx-split fork? We've been using that fork without the $any('*') work-around in our Angular 10 project. I see now that ngx-split is deprecated and angular-split is being actively maintained again.

  9. beeman commented on Oct 28, 2020

    @beeman
    Contributor

    @beeman — Wasn't this incorrect typing already resolved in your ngx-split fork? We've been using that fork without the $any('*') work-around in our Angular 10 project. I see now that ngx-split is deprecated and angular-split being actively maintained again.

    Correct, I solved it there so I know what's the fix.

    I'm deprecated my fork because the original author decided to hand over maintainence of this library.

    Just didn't get to merging back my fixes.

  10. KeithGillette commented on Jan 21, 2021

    @KeithGillette
    Author

    Any timeline for merging the fix for this issue from ngx-split, @beeman?

    We've been holding off on switching back from ngx-split to angular-split until this issue is closed, but now ngx-split throws a fatal error at runtime under angular@11.1.0:

    core.js:6156 ERROR Error: Uncaught (in promise): Error: ASSERTION ERROR: Expecting flags [Expected=> number === boolean <=Actual]
    Error: ASSERTION ERROR: Expecting flags [Expected=> number === boolean <=Actual]
    
  11. beeman commented on Jan 21, 2021

    @beeman
    Contributor

    @KeithGillette can't really give a timeline at this point, sorry. Simply too busy with other things.

    I think the workaround using $any('*') is relatively simple, so you might consider that.

  12. lf-novelt commented on Mar 1, 2021

    @lf-novelt
    Contributor

    thanks for the workaround.
    However I wonder if this is symply a typing issue, or an actual issue with the code, as the project is in TypeScript, so the typing are generated from the actual code, and the code really expects the size Input to be a Number as seen here

    private _size: number | null = null
    @Input() set size(v: number | null) {

    I am trying to find where this size === "*" case is handled in the source...

  13. beeman commented on Mar 1, 2021

    @beeman
    Contributor

    Hey @lf-novelt , if you check #289 you can see where it's set. Once I finish that PR it will work without the workaround.

  14. changed the title [-]Incorrect @Input size typing causes `error TS2322: Type 'string' is not assignable to type 'number'` when `tsconfig.json` `angularCompilerOptions.strictTemplates: true`[/-] [+]Incorrect @Input size typing when strictTemplates is enabled[/+] on Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions