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

es6 "Strict object literal assignment checking" breaks test files. #26

Closed
AGBrown opened this issue Sep 26, 2015 · 2 comments
Closed

es6 "Strict object literal assignment checking" breaks test files. #26

AGBrown opened this issue Sep 26, 2015 · 2 comments
Assignees
Milestone

Comments

@AGBrown
Copy link
Owner

AGBrown commented Sep 26, 2015

Discovered while testing #24

Reference: typescript 1.6 > breaking changes > Strict object literal assignment checking.

It is an error to specify properties in an object literal that were not specified on the target type, when assigned to a variable or passed for a parameter of a non-empty target type.

This relates to #24. During the upgrade to ts 1.6.2, and specifying that version in the package.json and the associated options in tsconfig.json, the test files failed to build. This was due to (for example) pouchdb-tests.ts#L292, which specifies a foo property, which is not on BaseDoc.

@fredgalvao introduced a fix during the work for #18, which added an indexer to some of the base types for the documents, and introduced a new base type for the db.

I propose a slightly more flexible approach. If we introduce a new base type for the db types (e.g. pouchdb.d.ts@37f648b7#36-39), it will allow the user to extend that, or the BaseDoc, type as they wish. We will also provide two extension d.ts files that will add indexers to each of those types. In this way the users can choose between the options in typescript 1.6 > breaking changes > Strict object literal assignment checking by choosing to use the core file only, import the extension files, or extend the base interfaces in their own way.

  1. "disabled with the --suppressExcessPropertyErrors compiler option.": core file only
  2. "add an indexer": extension files - /// reference the extension d.ts files that do this for you
  3. "explicitly specify them using union types instead of just specifying the base type.": core file only - this could be achieved by modifying method overloads to generic overloads which specify an upper bound for the type argument.
  4. "explicitly cast to the target type to avoid the warning message." core file only - the user can extend the existing docs, and use casts.
@AGBrown
Copy link
Owner Author

AGBrown commented Sep 26, 2015

TODO:

  • discuss and approve, get a +1 from @fredgalvao if we are going ahead
  • update readme.md appropriately

@AGBrown AGBrown added this to the p3.4.0-v0.1.0 milestone Sep 26, 2015
@AGBrown AGBrown self-assigned this Sep 26, 2015
AGBrown added a commit that referenced this issue Sep 26, 2015
…eople to relax es6 constraints on loose properties by putting a `[x: string]: any` on base types
AGBrown added a commit that referenced this issue Sep 27, 2015
…eople to relax es6 constraints on loose properties by putting a `[x: string]: any` on base types
@fredgalvao
Copy link
Contributor

I'd vote to simply get loose|plugins as part of the core, but having the option to choose will never hurt, so I'm okay with the proposed solution.

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

No branches or pull requests

2 participants