Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strictTemplates, Angular 9, Type 'string' is not assignable to type 'NgbPanel' #3619

Closed
ghost opened this issue Feb 24, 2020 · 10 comments · Fixed by #3623
Closed

strictTemplates, Angular 9, Type 'string' is not assignable to type 'NgbPanel' #3619

ghost opened this issue Feb 24, 2020 · 10 comments · Fixed by #3623

Comments

@ghost
Copy link

ghost commented Feb 24, 2020

Bug description:

Enabling the new strictTemplates flag in Angular 9's compiler options generates the following build error:

error TS2322: Type 'string' is not assignable to type 'NgbPanel'

pointing to any use of ngbPanelToggle i.e.

    <ng-template ngbPanelHeader let-opened="opened">
      <div class="d-flex align-items-center justify-content-between">
        <h5 class="m-0">First panel - {{ opened ? 'opened' : 'collapsed' }}</h5>
        <button ngbPanelToggle class="btn btn-link p-0">Toggle first</button>
      </div>
    </ng-template>

(taken from https://ng-bootstrap.github.io/#/components/accordion/examples#header)

Versions of Angular, ng-bootstrap and Bootstrap:

Angular: 9.0.2

ng-bootstrap: 6.0.0

Bootstrap: 4.4.1

@maxokorokov
Copy link
Member

@kknD7J3fPUGDMNR unfortunately at the moment I'd suggest you use the combination of:

"strictTemplates": true,
"strictInputTypes": false,

to disable the input type checks to "workaround" the problem. At the moment our public APIs don't fully conform to strictTemplates, but might in future.

@peterblazejewicz
Copy link
Contributor

to disable the input type checks to "workaround" the problem. At the moment our public APIs don't fully conform to strictTemplates, but might in future.

Can we have a list of things to change/overhaul in separate item, so we could iterate on them? Thx!

@maxokorokov maxokorokov added this to the 6.0.1 milestone Feb 26, 2020
@maxokorokov
Copy link
Member

@peterblazejewicz actually looking into it right now, not so many things to change. Will open a PR soon.

maxokorokov added a commit to maxokorokov/ng-bootstrap that referenced this issue Feb 26, 2020
Fixes the following use-cases for the public APIs:

1. Boolean `@Input`s like `disabled` where value is not required

```html
<component disabled></component>
```

by adding

```ts
static ngAcceptInputType_disabled: boolean | '';
```

2. All union types like `'vertical' | 'horizontal'`

```
// template
<nav ngbNav [orientation]="orientation"></nav>

// component
orientation = 'vertical';
```
by adding:

```ts
static ngAcceptInputType_orientation: string;
```

3. Cases where the directive selector matches the input with the optional value

```html
<button [ngbPanelToggle]="p"></button>
<button ngbPanelToggle></button>
```

by adding:

```ts
static ngAcceptInputType_ngbPanelToggle: NgbPanel | '';
```

Also makes all internal library templates to work with `strictTemplates`.

Fixes ng-bootstrap#3619
maxokorokov added a commit to maxokorokov/ng-bootstrap that referenced this issue Feb 26, 2020
Fixes the following use-cases for the public APIs:

1. Boolean `@Input`s like `disabled` where value is not required:

```html
<input ngbButton disabled></input>
```

by adding

```ts
static ngAcceptInputType_disabled: boolean | '';
```

2. All union types like `'vertical' | 'horizontal'`:

```
// template
<nav ngbNav [orientation]="orientation"></nav>

// component
orientation = 'vertical';
```
by adding:

```ts
static ngAcceptInputType_orientation: string;
```

3. Cases where the directive selector matches the input with the optional value

```html
<button [ngbPanelToggle]="p"></button>
<button ngbPanelToggle></button>
```

by adding:

```ts
static ngAcceptInputType_ngbPanelToggle: NgbPanel | '';
```

Also makes all internal library templates to work with `strictTemplates`.

Fixes ng-bootstrap#3619
maxokorokov added a commit that referenced this issue Feb 27, 2020
Fixes the following use-cases for the public APIs:

1. Boolean `@Input`s like `disabled` where value is not required:

```html
<input ngbButton disabled></input>
```

by adding

```ts
static ngAcceptInputType_disabled: boolean | '';
```

2. All union types like `'vertical' | 'horizontal'`:

```
// template
<nav ngbNav [orientation]="orientation"></nav>

// component
orientation = 'vertical';
```
by adding:

```ts
static ngAcceptInputType_orientation: string;
```

3. Cases where the directive selector matches the input with the optional value

```html
<button [ngbPanelToggle]="p"></button>
<button ngbPanelToggle></button>
```

by adding:

```ts
static ngAcceptInputType_ngbPanelToggle: NgbPanel | '';
```

Also makes all internal library templates to work with `strictTemplates`.

Fixes #3619
@andzejsw
Copy link

I have this error after update:
This likely means that the library (@ng-bootstrap/ng-bootstrap) which declares NgbModule has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.

@maxokorokov
Copy link
Member

@aleeeftw what update? please open a new issue following the template if you have any problems.

@aleeeftw
Copy link
Contributor

@maxokorokov Hmmm?!

@maxokorokov
Copy link
Member

sorry, @aleeeftw my bad, wrong mention. I meant @andzejsw :)

@andzejsw
Copy link

andzejsw commented Mar 2, 2020

Same error for me appears in @ng-bootstrap/ng-bootstrap version 6.0.0. Is it merged in Master or still it isn't fixed?

@maxokorokov
Copy link
Member

maxokorokov commented Mar 2, 2020

@andzejsw not yet released, but merged in master. Please either use master or wait for 6.0.1

@jkruse14
Copy link

@maxokorokov - forgive my ignorance, but how do I install the master branch? When I do npm install ng-bootstrap/ng-bootstrap#master it tells me to use yarn. When I try yarn add it says I do not have access. I know I must be missing something obvious

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants