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

Strict type check error is thrown when compiling with typeScript/Angular #1176

Open
temecom opened this issue May 6, 2024 · 3 comments
Open
Labels
bug Something isn't working

Comments

@temecom
Copy link

temecom commented May 6, 2024

Describe the Bug

When importing the form-js library a type error:

Member 'container' implicitly has an 'any' type.ts(7008)

is reported in file node_modules/@bpmn-io/form-js-viewer/dist/types/render/Renderer.d.ts preventing the typescript compilation to continue.

Steps to Reproduce

  1. Create an Angular project
ng new form-js-test
cd form-js-test
  1. Install form-js-viewer types
npm install @bpmn-io/form-js-viewer
  1. Generate a component
ng g c TestForm
  1. Update the test-form.component.ts file:
import { Component, OnInit } from '@angular/core';

import { Form, Schema } from '@bpmn-io/form-js-viewer';

@Component({
  selector: 'app-test-form',
  standalone: true,
  imports: [],
  templateUrl: './test-form.component.html',
  styleUrl: './test-form.component.scss'
})
export class TestFormComponent implements OnInit {
  form: Form; // Declare form as a class field
  schema: Schema = {
    type: "default",
    components: [
      {
        key: 'creditor',
        id: 'abcdef', 
        label: 'Creditor',
        type: 'textfield',
        validate: {
          required: true,
        },
      },
    ],
  };
  data = {
    creditor: 'John Doe Company',
  };

  constructor() { 
    this.form = new Form(); 
  }

  ngOnInit(): void {
    this.initializeForm();
  }

  initializeForm(): void {
    const container: HTMLElement | null= document.querySelector('#form-container'); 
    this.form = new Form({
      container:  container, // Explicitly define the type
    });
    
    this.form.importSchema(this.schema, this.data);

    // Add event listeners
    this.form.on('submit', this.onSubmit.bind(this));
    this.form.on('changed', 500, this.onFormChanged.bind(this));
  }

  onSubmit(event: any): void {
    console.log('Form <submit>', event);
    // Handle form submission here
  }

  onFormChanged(event: any): void {
    console.log('Form <changed>', event);
    // Handle form change here
  }
}

  1. Add a route to the form app.routes.ts
import { Routes } from '@angular/router';
import { TestFormComponent } from './test-form/test-form.component';

export const routes: Routes = [
    {path: 'form/test', component: TestFormComponent}

];

  1. Run the server
ng serve

  1. Open browser on address:
localhost:4200/form/test

Expected Behavior

Service compiles and renders.

Fix

Update Config declaration:

export type Config = {
    container:HTMLElement;
};

Environment

  • Host Angular
  • OS: WSL/Windows 11
  • Library version: latest
@temecom temecom added the bug Something isn't working label May 6, 2024
@vsgoulart
Copy link
Contributor

Hello @temecom , I believe the best solution for you would be to disable type checks on libraries via skipLibCheck, since this is third-party code your app has no control over

We sure want to improve our types but it's not a high priority for us right now.

@temecom
Copy link
Author

temecom commented May 7, 2024 via email

@MUSTJPI
Copy link

MUSTJPI commented May 16, 2024

Agree with the down sides...and mention that this was already signaled here : [https://github.com//issues/1153]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants