Skip to content
This repository has been archived by the owner on Mar 20, 2022. It is now read-only.

Add type declarations #84

Closed
wants to merge 1 commit into from
Closed

Add type declarations #84

wants to merge 1 commit into from

Conversation

unindented
Copy link
Contributor

No description provided.

@unindented
Copy link
Contributor Author

@blakeembrey could you please review?

@blakeembrey
Copy link

@unindented Just remember that TypeScript is going to do structural type checking, so some of those values already appear to be assignable to each other.

@@ -0,0 +1,67 @@
interface EntitySchemaOptions {

Choose a reason for hiding this comment

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

You will probably want to export these interfaces/types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All types that are used by public APIs should be exported? So I should export everything in this file, right?

Choose a reason for hiding this comment

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

Pretty much, export everything.

@unindented
Copy link
Contributor Author

@blakeembrey Forgive my ignorance, I'm very new to type systems. Could you give me an example to illustrate the fact that "some of those values already appear to be assignable to each other", and what consequences it has?

@unindented
Copy link
Contributor Author

@gaearon What are your thoughts on adding type definitions to the repo? I have an attempt at TypeScript definitions here, and could work on a .flowconfig file...

@blakeembrey
Copy link

@unindented This is the basic gist: http://www.typescriptlang.org/play/index.html#src=class%20Foo%20%7B%7D%0A%0Aclass%20Bar%20%7B%7D%0A%0Afunction%20x%20(foo%3A%20Foo)%20%7B%7D%0A%0Ax(new%20Bar())%0Ax('test')%0Ax(10)%0Ax(Foo)

Since all the interfaces are structurally the same, you aren't actually doing any type checking.

@unindented
Copy link
Contributor Author

@blakeembrey Aha, understood. Adding empty interfaces is almost equivalent to any, so my union type was useless.

I've updated the PR with proper types.

@unindented
Copy link
Contributor Author

@paularmstrong @gaearon do you think the type definitions belong to this repo? There are ways to host the type definitions in a separate repo, but then we wouldn't be able to reference them in the package.json, and it would add some friction for users, as they'd have to manually install them for their projects using a tool like typings.

@paularmstrong
Copy link
Owner

I don't see why normalizr shouldn't include its own type declarations. However, is there a way to have an automated test ensure that these are updated when necessary?

@unindented
Copy link
Contributor Author

Umm, I don't know the best way to ensure type declarations are up-to-date. @blakeembrey what do you suggest?

@gaearon
Copy link
Contributor

gaearon commented Apr 19, 2016

However, is there a way to have an automated test ensure that these are updated when necessary?

If we add them, we should add tests for them.
I’m also ignorant of the process, here’s what community did with Redux:

reduxjs/redux#1413
reduxjs/redux#1526
reduxjs/redux#1537
reduxjs/redux#1545

These include tests.

@unindented
Copy link
Contributor Author

Ok, I'll follow the same approach.

@blakeembrey
Copy link

Yes, that's what we usually do too. You can have some valid code and make sure it compiles validly with tsc, or even run some of the test suite with TypeScript.

@unindented
Copy link
Contributor Author

unindented commented Jun 4, 2016

Hey @paularmstrong, I finally got around to this.

I've updated the definitions with the latest changes that were made (getMeta, etc.) and added tests that cover all signatures (following the same pattern that redux uses).

Let me know what you think!

@paularmstrong paularmstrong modified the milestone: 2.2.0 Jun 6, 2016
@paularmstrong
Copy link
Owner

Thanks @unindented. I'll merge this soon for v2.2.0

@unindented
Copy link
Contributor Author

@paularmstrong any planned date for v2.2.0?

@paularmstrong
Copy link
Owner

Been on vacation. Maybe can shoot for late next week. If there's a strong request, though, I could defer the docs/examples/tests updates that we need.

@unindented
Copy link
Contributor Author

Tests are already in this PR. Other projects, like redux, assume people who are using TypeScript know how to consume types, so they don't add specific docs or examples.

@paularmstrong
Copy link
Owner

@unindented I mean #105, #106, and #107

@lock
Copy link

lock bot commented May 7, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot added the Outdated label May 7, 2018
@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants