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

feat: add types #39

Merged
merged 11 commits into from
Mar 3, 2021
Merged

feat: add types #39

merged 11 commits into from
Mar 3, 2021

Conversation

achingbrain
Copy link
Member

Adds ts type generation and fixes all tsc errors.

Adds ts type generation and fixes all tsc errors.
package.json Outdated
"test:node": "aegir test --target node",
"test:browser": "aegir test --target browser",
"test": "aegir test",
"lint": "aegir lint && aegir lint-package-json",
"release": "aegir release",
"release-minor": "aegir release --type minor",
"release-major": "aegir release --type major",
"build": "aegir build",
"prepublishOnly": "aegir build",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To publish a minified bundle? Have removed it, shout if it's actually useful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I miss any policy change for our JS libs? Why would we NOT provide a prebuilt browser bundle?

It is documented in https://github.com/ipfs-shipyard/is-ipfs#in-the-browser-through-script-tag so for now I've restored prepublishOnly in 2a03f54

package.json Outdated Show resolved Hide resolved
Copy link

@Gozala Gozala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor suggestion to avoid hard coding aegir path. Otherwise looks good to me.

@@ -0,0 +1,10 @@
{
"extends": "./node_modules/aegir/src/config/tsconfig.aegir.json",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not assume where exactly aegir is.

Suggested change
"extends": "./node_modules/aegir/src/config/tsconfig.aegir.json",
"extends": "aegir/src/config/tsconfig.aegir.json",

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That started failing recently and we don't know why yet.

Copy link
Member Author

@achingbrain achingbrain Mar 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typescript team broke this a minor release last week:

> [email protected] prepare
> aegir build --no-bundle

[11:11:07] Clean ./dist [started]
[11:11:07] Clean ./dist [completed]
[11:11:07] Generate types [started]
tsconfig-types.aegir.json:1:12 - error TS6053: File 'aegir/src/config/tsconfig.aegir.json' not found.

😭

@Gozala
Copy link

Gozala commented Feb 26, 2021

It might be worth considering changing some of the isFoo style functions to more type friendly ones like asFoo(x:any): Foo|null so that type checker is able to refine the type. Unfortunately isFoo(x:any): x is Foo is not applicable here because I do not believe these functions check if passed value is Foo but test whether value could potentially be casted to Foo.

src/index.js Outdated Show resolved Hide resolved
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gozala I'd argue that the purpose of this library is to validate strings/bytes and return clear booleans specifically to avoid false-negatives when comparing types in (non-TS) userland. At least that is why I started using it in ipfs-companion (wanted deterministic CID.isCID i could trust)

Anyway, adding types sounds sensible, are we good with this as it is now, or should we wait till

tsconfig-types.aegir.json:1:12 - error TS6053: File 'aegir/src/config/tsconfig.aegir.json' not found.

Gets resolved upstream?

.travis.yml Show resolved Hide resolved
@@ -29,28 +30,26 @@
"url": "https://github.com/ipfs/is-ipfs.git"
},
"scripts": {
"prepare": "aegir build --no-bundle",
Copy link
Member

@lidel lidel Mar 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hugomrdias What does --no-bundle do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It skips the browser bundle step as you don't need it during development, i.e. it only generates types from the jsdoc comments.

@achingbrain
Copy link
Member Author

tsconfig-types.aegir.json:1:12 - error TS6053: File 'aegir/src/config/tsconfig.aegir.json' not found.

This would only start happening if we apply the suggestion from #39 (comment) which we should not do.

I would not wait on it getting resolved first, the ts team move at their own cadence with their own conventions.

Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

(I've restored browser bundle in 2a03f54 because it is still in readme)

@lidel lidel merged commit 4a96bde into master Mar 3, 2021
@lidel
Copy link
Member

lidel commented Mar 3, 2021

This shipped as [email protected]

@lidel lidel deleted the feat/add-types branch March 3, 2021 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants