ember-concurrency icon indicating copy to clipboard operation
ember-concurrency copied to clipboard

Superfluous triple-slash directives generated by Glint produce Glint errors (manually removing them fixes this)

Open fry69 opened this issue 1 year ago • 8 comments

In a fresh 5.6.0 install (ember new app --typescript) with just ember-concurrency 4.0.0 and most recent Glint (ember install ember-concurrency and following the basic instructions from https://typed-ember.gitbook.io/glint/environments/ember/installation), I get these errors when I run Glint on the terminal:

$ ./node_modules/.bin/glint
node_modules/ember-concurrency/declarations/helpers/cancel-all.d.ts:1:23 - error TS2688: Cannot find type definition file for 'ember-source/types/preview/@ember/component/-private/signature-utils'.

1 /// <reference types="ember-source/types/preview/@ember/component/-private/signature-utils" />
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/ember-concurrency/declarations/helpers/cancel-all.d.ts:2:23 - error TS2688: Cannot find type definition file for 'ember-source/types/preview/@ember/component/helper'.

2 /// <reference types="ember-source/types/preview/@ember/component/helper" />
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/ember-concurrency/declarations/helpers/perform.d.ts:1:23 - error TS2688: Cannot find type definition file for 'ember-source/types/preview/@ember/component/helper'.

1 /// <reference types="ember-source/types/preview/@ember/component/helper" />
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/ember-concurrency/declarations/helpers/task.d.ts:1:23 - error TS2688: Cannot find type definition file for 'ember-source/types/preview/@ember/component/-private/signature-utils'.

1 /// <reference types="ember-source/types/preview/@ember/component/-private/signature-utils" />
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/ember-concurrency/declarations/helpers/task.d.ts:2:23 - error TS2688: Cannot find type definition file for 'ember-source/types/preview/@ember/component/helper'.

2 /// <reference types="ember-source/types/preview/@ember/component/helper" />

There are no preview types in ember-source for 5.6.0?

$ ls node_modules/ember-source/types
publish.mjs	stable

Looks like ember-page-title has had a similar issue with generated triple-slash directives, see https://github.com/ember-cli/ember-page-title/pull/283

I can confirm that manually removing these generated /// lines fixes this issue for me.

fry69 avatar Feb 08 '24 10:02 fry69

@nullvoxpopuli can you confirm that applying the same solution/codefix from https://github.com/ember-cli/ember-page-title/pull/283 would be the proper course of action here?

machty avatar Feb 09 '24 02:02 machty

Can confirm. These folks have used that solution so far: https://github.com/NullVoxPopuli/fix-bad-declaration-output/network/dependents

Gonna add it to the ts blueprint for v2 addons

NullVoxPopuli avatar Feb 09 '24 02:02 NullVoxPopuli

Until the fix has landed and file in the node-modules directory tend to get replaced to their original state, here is a python script to remove those triple-slash lines.

import os
import re

dir_path = './node_modules/ember-concurrency/declarations/helpers'

for file_name in os.listdir(dir_path):
    if file_name.endswith('.d.ts'):
        file_path = os.path.join(dir_path, file_name)
        
        with open(file_path, 'r') as f:
            file_contents = f.read()
        
        file_contents = re.sub('^/// <reference types="[^"]+" />', '', file_contents, flags=re.MULTILINE)
        
        with open(file_path, 'w') as f:
            f.write(file_contents)

fry69 avatar Feb 09 '24 10:02 fry69

Was digging in to this yesterday, and it looks like the generated declarations may slightly be wrong? They're not using declare when exporting a const, and that breaks the ts parser used in fix-bad-declaration-output

NullVoxPopuli avatar Feb 09 '24 13:02 NullVoxPopuli

Should we be using generated declarations at all? Last I knew ember-concurrency was still using a hand-rolled index.d.ts and the bulk of the actual implementation was still in JS, so I wonder if things were unintentionally switched over as part of the v2 migration.

Edit: ah, I was getting trolled by the start:types script not having the extra copy step cp src/index.d.ts declarations.d.ts step that the build:types script has.

dfreeman avatar Feb 27 '24 15:02 dfreeman

Any updates on this one?

I'm using:

"ember-source": "5.10.2",
"ember-concurrency": "4.0.2",

and I'm getting:

node_modules/ember-concurrency/declarations/helpers/perform.d.ts:1:23 - error TS2688: Cannot find type definition file for 'ember-source/types/prev…
│ [types] 
│ [types] 1 /// <reference types="ember-source/types/preview/@ember/component/helper" />

esbanarango avatar Aug 09 '24 16:08 esbanarango

ember-concurrency has a bug in their types, and they may need to add this inline-rollup plugin: https://github.com/universal-ember/ember-primitives/blob/main/ember-primitives/rollup.config.mjs#L34

 {
      name: "Build Declarations",
      closeBundle: async () => {
        /**
         * Generate the types (these include /// <reference types="ember-source/types"
         * but our consumers may not be using those, or have a new enough ember-source that provides them.
         */
        console.log("Building types");
        await execaCommand(`pnpm glint --declaration`, { stdio: "inherit" });
        /**
         * https://github.com/microsoft/TypeScript/issues/56571#
         * README: https://github.com/NullVoxPopuli/fix-bad-declaration-output
         */
        console.log("Fixing types");
        await fixBadDeclarationOutput("declarations/**/*.d.ts", [
          ["TypeScript#56571", { types: "all" }],
          "Glint#628",
          "Glint#697",
        ]);
        console.log("⚠️ Dangerously (but neededly) fixed bad declaration output from typescript");
      },

I ultimately consider this a bug with TypeScript itself though, because they don't have a story for peer-provided types at all.

NullVoxPopuli avatar Aug 09 '24 17:08 NullVoxPopuli

Can confirm that to user ember-concurrency 4.0.2 with a new-enough ember-source (which lacks types/preview since they're not preview anymore) I had to patch:

diff --git a/declarations/helpers/perform.d.ts b/declarations/helpers/perform.d.ts
index 140c903b9428c57f1de4c66e3a4143a77742f5ea..989e429ba29ec126ce603b0cb0f132339094b2ce 100644
--- a/declarations/helpers/perform.d.ts
+++ b/declarations/helpers/perform.d.ts
@@ -1,4 +1,3 @@
-/// <reference types="ember-source/types/preview/@ember/component/helper" />
 import type { Task } from '../index';
 type PerformParams = [task: Task<any, any[]>, ...args: any[]];
 export declare function performHelper(args: PerformParams, hash: any): (...innerArgs: any[]) => any;

ef4 avatar Sep 23 '24 22:09 ef4