machty / ember-concurrency

ember-concurrency is an Ember Addon that enables you to write concise, worry-free, cancelable, restartable, asynchronous tasks.
http://ember-concurrency.com
MIT License
691 stars 155 forks source link

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

Open fry69 opened 4 months ago

fry69 commented 4 months ago

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.

machty commented 4 months ago

@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?

NullVoxPopuli commented 4 months ago

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

fry69 commented 4 months ago

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)
NullVoxPopuli commented 4 months ago

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

dfreeman commented 4 months ago

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.