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

Improve typehint on Attributes #154

Closed
Tracked by #7
nandi95 opened this issue Dec 6, 2021 · 1 comment · Fixed by #178
Closed
Tracked by #7

Improve typehint on Attributes #154

nandi95 opened this issue Dec 6, 2021 · 1 comment · Fixed by #178
Labels
enhancement New feature or request

Comments

@nandi95
Copy link
Collaborator

nandi95 commented Dec 6, 2021

Update type to specify value type so getAttributes().myKey will correctly typehint and not be unknown

Already started the work but is is still causing issues because of the model index signature:

export type Attributes<
    M extends HasAttributes = HasAttributes
    // string index falls back to the model index signature
> = { [P in keyof M extends AttributeKeys<M> ? keyof M : never]: M[P] };


export type KeysNotMatching<T, V> = KeysNotMatching2<keyof T, T, V>;
// Using this intermediate type to force distribution.
type KeysNotMatching2<Keys extends keyof T, T, V> = Keys extends unknown ? KeyIsAttribute<Keys, T, V> : never;
type KeyIsAttribute<Key extends keyof T, T, V> = T[Key] extends V ? never : Key;
@nandi95 nandi95 mentioned this issue Dec 6, 2021
7 tasks
@nandi95 nandi95 added the enhancement New feature or request label Dec 22, 2021
@nandi95 nandi95 changed the title Fix typehint on Attributes Improve typehint on Attributes Dec 22, 2021
nandi95 added a commit to nandi95/framework-1 that referenced this issue Jan 23, 2022
@nandi95 nandi95 linked a pull request Jan 23, 2022 that will close this issue
nandi95 added a commit that referenced this issue Jan 26, 2022
## Docs
* docs: updated pagination recipe
* docs: corrected pagination example
  * The exists method has taken the `_lastSyncedAt` property into account and here it was not set before
* docs: adjust wording in doc blocks
* docs(services): noted `handleError` is now async
* docs(query-builder): added documentation for `resetQueryParameters`
* docs: fixed grammar mistakes
* docs(factory): updated examples to be in-line with mocks
* docs(api-calls): updated methods to preferred uppercase
* docs: updated recipe to use the new typing
* docs(timestamps): updated attribute name getter method names
    * Linked: 114176e
* docs: fixed typo in test name
* docs: updated pagination recipe to handle model constructors
* docs(api-calls): updated to uppercase method names
  * Updated all method argument to `call` to uppercase for consistency
* docs: fixed examples
* docs(api-calls): updated method name to uppercase
  * change missed from 03486f1

## Perf
* perf(query-builder): simplified withs deduplication

## Feature
* feat(services): made handleError async on ApiResponseHandler
* feat(api-calls): added default type argument
  * While this is invalid, from the outside TS still figures the current `this` correctly
* feat(query-builder): changed `resetQueryParameters` access to public
* feat(api-calls): export `Method` type
* feat(services): widened request type on ApiResponse
* feat(services): added HEAD request handling
* feat(services): improve typings of services call and handle method
* feat(attributes): improved `Attributes` type inference
    * Resolves #154
* feat(attributes): improved `only` method's typing
* feat(attributes): improved `except` typing
* feat(attributes): improved typings on attribute management methods
    * Following have been updated:
      `getOriginal`
      `getRawOriginal`
      `getChanges`
      `getDeletedAttributes`
      `getNewAttributes`
* feat: updated static methods returning models to infer type from `this`
* feat: updated some static inference to not use error ignoring
    * Updates related to: 63ed0be
* feat(model): added `create` method
    * This allows to constructing a model more fluently

## Fix
* fix(model): updated missed distinctBy in the clone method
* fix(attributes): fixed casting methods typing to accept mixed values
* fix(api-calls): pass the response attributes to the constructor
  * This also cleans up the code a little
* fix(services): normalised fetch methods
  * `patch` could failed with lowercase method name
* fix(api-calls): updated typing to be inclusive of each other on `get`
* fix(relations): fixed `addRelation` typing to accept subclass of a model
* fix: fixed outstanding eslint and typing errors
* fix(model-collection): fixed wrong typing of `toJSON`
    * Issue introduced in b4d6db4
* fix(**BREAKING CHANGE**): renamed timestamp name methods
  * Renamed the following:
    `getDeletedAtColumn` -> `getDeletedAtName`
    `getCreatedAtColumn` -> `getCreatedAtName`
    `getUpdatedAtColumn` -> `getUpdatedAtName`

## Test
* test(timestamps): tested `restore` accepting server deletedAt value
* test: added initial baseEndpoint in testing
* test(services): added missing test updates
    * Updates missed from a07b22a
* test(attributes): fixed failing guarding tests
* test(services): added missing test updates
    * Updates missed from a07b22a
* test(relations): updated testing to use the new typings
* test(model): updated to use new typings
* test(api-calls): added missing data unwrap test
* test(api-calls): added missing endpoint getter test

## Refactor
* refactor(services): simplified `handleError` in response handler
* refactor(attributes): simplified `getAttribute` override typing
* refactor(factory): update return types of mock factories
* refactor(model-collection): updated `toJSON` typing
  * updated `toJSON` typing to track the model's `toJSON`

## Chore
* chore: incremented package version
* chore: added new eslint rule
* chore: moved todos into github
* chore(deps): updated non-breaking dependencies
  * @commitlint/prompt-cli
  * @types/uuid
  * @typescript-eslint/eslint-plugin
  * @typescript-eslint/parser
  * commitlint
  * eslint
  * eslint-plugin-jest
  * lint-staged
  * qs
  * rollup
  * typedoc
  * typescript
* chore(deps-dev): updated breaking change dependencies
  * semantic-release

## Style
* style: fixed eslint issues

## Continuous Integration
* ci: added matrix values explanation
@nandi95
Copy link
Collaborator Author

nandi95 commented Jan 26, 2022

Resolved by #178

@nandi95 nandi95 closed this as completed Jan 26, 2022
nandi95 added a commit that referenced this issue Jan 26, 2022
## Docs 
* docs: updated pagination recipe 
* docs: corrected pagination example 
  * The exists method has taken the `_lastSyncedAt` property into account and here it was not set before 
* docs: adjust wording in doc blocks 
* docs(services): noted `handleError` is now async 
* docs(query-builder): added documentation for `resetQueryParameters` 
* docs: fixed grammar mistakes 
* docs(factory): updated examples to be in-line with mocks 
* docs(api-calls): updated methods to preferred uppercase 
* docs: updated recipe to use the new typing 
* docs(timestamps): updated attribute name getter method names 
    * Linked: 114176e 
* docs: fixed typo in test name 
* docs: updated pagination recipe to handle model constructors 
* docs(api-calls): updated to uppercase method names 
  * Updated all method argument to `call` to uppercase for consistency 
* docs: fixed examples 
* docs(api-calls): updated method name to uppercase 
  * change missed from 03486f1 
 
## Perf 
* perf(query-builder): simplified withs deduplication 
 
## Feature 
* feat(services): made handleError async on ApiResponseHandler 
* feat(api-calls): added default type argument 
  * While this is invalid, from the outside TS still figures the current `this` correctly 
* feat(query-builder): changed `resetQueryParameters` access to public 
* feat(api-calls): export `Method` type 
* feat(services): widened request type on ApiResponse 
* feat(services): added HEAD request handling 
* feat(services): improve typings of services call and handle method 
* feat(attributes): improved `Attributes` type inference 
    * Resolves #154 
* feat(attributes): improved `only` method's typing 
* feat(attributes): improved `except` typing 
* feat(attributes): improved typings on attribute management methods 
    * Following have been updated: 
      `getOriginal` 
      `getRawOriginal` 
      `getChanges` 
      `getDeletedAttributes` 
      `getNewAttributes` 
* feat: updated static methods returning models to infer type from `this` 
* feat: updated some static inference to not use error ignoring 
    * Updates related to: 63ed0be 
* feat(model): added `create` method 
    * This allows to constructing a model more fluently 
 
## Fix 
* fix(model): updated missed distinctBy in the clone method 
* fix(attributes): fixed casting methods typing to accept mixed values 
* fix(api-calls): pass the response attributes to the constructor 
  * This also cleans up the code a little 
* fix(services): normalised fetch methods 
  * `patch` could failed with lowercase method name 
* fix(api-calls): updated typing to be inclusive of each other on `get` 
* fix(relations): fixed `addRelation` typing to accept subclass of a model 
* fix: fixed outstanding eslint and typing errors 
* fix(model-collection): fixed wrong typing of `toJSON` 
    * Issue introduced in b4d6db4 
* fix(**BREAKING CHANGE**): renamed timestamp name methods 
  * Renamed the following: 
    `getDeletedAtColumn` -> `getDeletedAtName` 
    `getCreatedAtColumn` -> `getCreatedAtName` 
    `getUpdatedAtColumn` -> `getUpdatedAtName` 
 
## Test 
* test(timestamps): tested `restore` accepting server deletedAt value 
* test: added initial baseEndpoint in testing 
* test(services): added missing test updates 
    * Updates missed from a07b22a 
* test(attributes): fixed failing guarding tests 
* test(services): added missing test updates 
    * Updates missed from a07b22a 
* test(relations): updated testing to use the new typings 
* test(model): updated to use new typings 
* test(api-calls): added missing data unwrap test 
* test(api-calls): added missing endpoint getter test 
 
## Refactor 
* refactor(services): simplified `handleError` in response handler 
* refactor(attributes): simplified `getAttribute` override typing 
* refactor(factory): update return types of mock factories 
* refactor(model-collection): updated `toJSON` typing 
  * updated `toJSON` typing to track the model's `toJSON` 
 
## Chore 
* chore: incremented package version 
* chore: added new eslint rule 
* chore: moved todos into github 
* chore(deps): updated non-breaking dependencies 
  * @commitlint/prompt-cli 
  * @types/uuid 
  * @typescript-eslint/eslint-plugin 
  * @typescript-eslint/parser 
  * commitlint 
  * eslint 
  * eslint-plugin-jest 
  * lint-staged 
  * qs 
  * rollup 
  * typedoc 
  * typescript 
* chore(deps-dev): updated breaking change dependencies 
  * semantic-release 
 
## Style 
* style: fixed eslint issues 
 
## Continuous Integration 
* ci: added matrix values explanation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant