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

TypteScript compilation errors in dependent project with certain tsconfig settings #6360

Closed
ktbytechibong opened this issue Aug 19, 2022 · 3 comments
Labels
component: TypeScript issue: bug Describes why the code or behaviour is wrong

Comments

@ktbytechibong
Copy link
Contributor

ktbytechibong commented Aug 19, 2022

I have a TS project that depends on blockly. When upgrading my blockly version to 9.0.0-beta.0, I have the following errors when doing tsc --watch in my project:

[11:27:56 AM] Starting compilation in watch mode...

node_modules/blockly/core/block.ts:1416:22 - error TS2339: Property 'substring' does not exist on type 'any[]'.

1416         text = (text.substring(0, opt_maxLength - 3) + '...') as
                          ~~~~~~~~~

node_modules/blockly/core/block.ts:1420:5 - error TS2322: Type 'any[]' is not assignable to type 'string'.

1420     return text;
         ~~~~~~~~~~~~

node_modules/blockly/core/field_registry.ts:71:7 - error TS2352: Conversion of type 'Field' to type 'IRegistrableField' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Property 'fromJson' is missing in type 'Field' but required in type 'IRegistrableField'.

71       registry.getObject(registry.Type.FIELD, options['type']) as
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72           IRegistrableField |
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
73       null;
   ~~~~~~~~~~

  node_modules/blockly/core/interfaces/i_registrable_field.ts:30:3
    30   fromJson: fromJson;
         ~~~~~~~~
    'fromJson' is declared here.

node_modules/blockly/core/generator.ts:162:17 - error TS2339: Property 'replace' does not exist on type 'any[]'.

162     code = code.replace(/\n\s+$/, '\n');
                    ~~~~~~~

node_modules/blockly/core/generator.ts:163:17 - error TS2339: Property 'replace' does not exist on type 'any[]'.

163     code = code.replace(/[ \t]+\n/g, '\n');
                    ~~~~~~~

node_modules/blockly/core/generator.ts:164:5 - error TS2322: Type 'any[]' is not assignable to type 'string'.

164     return code;
        ~~~~~~~~~~~~

node_modules/blockly/core/utils/toolbox.ts:428:3 - error TS2322: Type 'string | Element' is not assignable to type 'Element'.
  Type 'string' is not assignable to type 'Element'.

428   return toolboxDef;

To Reproduce

Have a project that depends on blockly@9.0.0-beta.0 with the following tsconfig.json file. Note that the above errors cannot be bypassed even when setting skipLibCheck to true.

{
    "compileOnSave": true,
    "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "sourceMap": false,
        "removeComments": true,
        "listEmittedFiles": false,
        "newLine": "LF",
        "downlevelIteration" : true,
        "incremental": true,
        "jsx": "react",
        "resolveJsonModule": true,
        "lib": [
            "dom",
            "es2021",
            "WebWorker",
        ],
        "skipLibCheck": true,
        "baseUrl": ".",
        "paths": {
            "shared/*": ["src/shared/*"]
        },
    },
}

An easier way to reproduce the same errors is to mess with the tsconfig.json file of the blockly project directly: (Changes are marked with ****). Then run tsc --watch.

{
  "include": [
    "core/**/*",  // N.B.: also pulls in closure/goog/goog.js if needed.
    "closure/**/*",  // Just for ouptut directory structure.
  ],
  "exclude": [
    "core/blockly.js"
  ],
  "compilerOptions": {
    "allowJs": false, // **** set this to false
    "declaration": true,
    "sourceMap": true,

    "module": "ES2015",
    "moduleResolution": "node",
    "target": "ES2020",
    "strict": false, // **** set this to false
    
    // **** add the 'lib' and 'skipLibCheck' entries
    "lib": [
        "dom",
        "es2021",
        "WebWorker",
    ],
    "skipLibCheck": true,
  }
}

Desktop:

  • OS: Ubuntu 22.04
  • tsc: 4.4.3
@ktbytechibong ktbytechibong added the issue: triage Issues awaiting triage by a Blockly team member label Aug 19, 2022
@ktbytechibong
Copy link
Contributor Author

The TS errors seem relatively straightforward to fix. I'll submit a PR.

@btw17
Copy link
Member

btw17 commented Aug 19, 2022

Seeing node_modules/blockly/core/utils/toolbox.ts:428:3 leads me to believe this is actually related to the beta package including .ts files alongside the .d.ts & minified .js files. (I ran into a similar issue earlier. Note in the node_modules that node_modules/blockly/core/utils/toolbox.d.ts also exists!) An update is coming soon that will remove the .ts files from the package (see #6362).

You can confirm this is the problem by removing the *.ts files from the package.

There's some environmental setup they have with the original .ts that won't work by default with other packages, though it should be resolved in the .d.ts files.

@BeksOmega BeksOmega added component: TypeScript issue: bug Describes why the code or behaviour is wrong and removed issue: triage Issues awaiting triage by a Blockly team member labels Aug 19, 2022
@ktbytechibong
Copy link
Contributor Author

@btw17 ahh.. that is indeed the problem. Removing the *.ts files from the node_modules folder fixed the errors.

BeksOmega pushed a commit that referenced this issue Sep 6, 2022
…6360) (#6361)

* fix: TS errors on dependent projects with certain tsconfig settings (#6360)

* Address PR comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: TypeScript issue: bug Describes why the code or behaviour is wrong
Projects
None yet
Development

No branches or pull requests

3 participants