Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

fix: fix generated types to missing import #86

Merged
merged 1 commit into from
Jan 28, 2022

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Jan 27, 2022

Motivation
Got this error when using this in lodestar

@chainsafe/lodestar: $ tsc -p tsconfig.build.json
@chainsafe/lodestar: ../../node_modules/datastore-core/types/src/index.d.ts:20:23 - error TS2304: Cannot find name 'ShardImport'.
@chainsafe/lodestar: 20     ShardBase: typeof ShardImport.ShardBase;
@chainsafe/lodestar:                          ~~~~~~~~~~~
@chainsafe/lodestar: ../../node_modules/datastore-core/types/src/index.d.ts:21:20 - error TS2304: Cannot find name 'ShardImport'.
@chainsafe/lodestar: 21     Prefix: typeof ShardImport.Prefix;
@chainsafe/lodestar:                       ~~~~~~~~~~~
@chainsafe/lodestar: ../../node_modules/datastore-core/types/src/index.d.ts:22:20 - error TS2304: Cannot find name 'ShardImport'.
@chainsafe/lodestar: 22     Suffix: typeof ShardImport.Suffix;
@chainsafe/lodestar:                       ~~~~~~~~~~~
@chainsafe/lodestar: ../../node_modules/datastore-core/types/src/index.d.ts:23:24 - error TS2304: Cannot find name 'ShardImport'.
@chainsafe/lodestar: 23     NextToLast: typeof ShardImport.NextToLast;
@chainsafe/lodestar:                           ~~~~~~~~~~~
@chainsafe/lodestar: Found 4 errors.
@chainsafe/lodestar: error Command failed with exit code 2.

Description

@welcome
Copy link

welcome bot commented Jan 27, 2022

Thank you for submitting this PR!
A maintainer will be here shortly to review it.
We are super grateful, but we are also overloaded! Help us by making sure that:

  • The context for this PR is clear, with relevant discussion, decisions
    and stakeholders linked/mentioned.

  • Your contribution itself is clear (code comments, self-review for the
    rest) and in its best form. Follow the code contribution
    guidelines

    if they apply.

Getting other community members to do a review would be great help too on complex PRs (you can ask in the chats/forums). If you are unsure about something, just leave us a comment.
Next steps:

  • A maintainer will triage and assign priority to this PR, commenting on
    any missing things and potentially assigning a reviewer for high
    priority items.

  • The PR gets reviews, discussed and approvals as needed.

  • The PR is merged by maintainers when it has been approved and comments addressed.

We currently aim to provide initial feedback/triaging within two business days. Please keep an eye on any labelling actions, as these will indicate priorities and status of your contribution.
We are very grateful for your contribution!

@achingbrain
Copy link
Member

I think this breaks the transpiled CJS version as it changes the shape of the exported object:

// src/index.js
import * as ShardImport from './shard.js'

export const shard = {
  ...ShardImport
}
// dist/cjs/index.js
var shard$1 = require('./shard.js');
const shard = shard$1;

exports.shard = shard;

vs

// src/index.js
export * as shard from './shard.js'
// dist/cjs/index.js
var shard$1 = require('./shard.js');
const shard = shard$1;

exports.PREFIX = shard.PREFIX;
exports.Prefix = shard.Prefix;
exports.README_FN = shard.README_FN;
exports.SHARDING_FN = shard.SHARDING_FN;
exports.ShardBase = shard.ShardBase;
exports.Suffix = shard.Suffix;
exports.parseShardFun = shard.parseShardFun;
exports.readShardFun = shard.readShardFun;

If I change /src/index.js to:

export const Errors = ErrorsImport
export const shard = ShardImport

I get:

export { BaseDatastore } from "./base.js";
export { MemoryDatastore } from "./memory.js";
export { KeyTransformDatastore } from "./keytransform.js";
export { ShardingDatastore } from "./sharding.js";
export { MountDatastore } from "./mount.js";
export { TieredDatastore } from "./tiered.js";
export { NamespaceDatastore } from "./namespace.js";
export const Errors: typeof ErrorsImport;
export const shard: typeof ShardImport;
export type Shard = import("./types").Shard;
export type KeyTransform = import("./types").KeyTransform;
import * as ErrorsImport from "./errors.js";
import * as ShardImport from "./shard.js";
//# sourceMappingURL=index.d.ts.map

Can you try overwriting the generated index.d.ts with the above locally and see if it fixes the problem?

@twoeths twoeths force-pushed the tuyen/fix-typing-issue branch from 1972a1f to 9570f10 Compare January 28, 2022 06:20
@twoeths
Copy link
Contributor Author

twoeths commented Jan 28, 2022

Thanks @achingbrain for the detail, it works great!

@twoeths twoeths requested a review from achingbrain January 28, 2022 06:21
@achingbrain achingbrain changed the title Fix generated types fix: fix generated types to missing import Jan 28, 2022
@achingbrain achingbrain merged commit 8805e71 into ipfs:master Jan 28, 2022
github-actions bot pushed a commit that referenced this pull request Jan 28, 2022
### [7.0.1](v7.0.0...v7.0.1) (2022-01-28)

### Bug Fixes

* fix generated types to missing import ([#86](#86)) ([8805e71](8805e71)), closes [#85](#85)
@github-actions
Copy link

🎉 This PR is included in version 7.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

Typing issue in v7.0.0
2 participants