Skip to content

Fix Record#get type checking #1015

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

Merged
merged 2 commits into from
Nov 15, 2022
Merged

Conversation

bigmontz
Copy link
Contributor

@bigmontz bigmontz commented Nov 10, 2022

This method was not correctly type checking the key argument. Keys are not in the Entries where being accepted without trigger typescript errors.

The error was being cause because the method was not relying in the keys set in the Entries, but the ones came from the constructor and from the field lookup.

The keys came from constructor and field lookup are not meant to be used in the client code, since they are internal.

This way, the error was solving by strict get method key type for consider only indexes (number) and Key originated from the Entries.

Example:

interface Person {
   age: Integer
   name: string
}

const p: Record<Person> = // get record form somewhere

const age: Integer = p.get('age')
const name: string = p.get('name')

// @ts-expected-error This error was not being point out before
const nonExistingKey = p.get('non-existing-key')

⚠️ This type definitions are not asserted in runtime. Thus mismatched type records coming from the database will not trigger type errors.

This method was not correctly type checking the key argument.
Keys are not in the Entries where being accepted without trigger typescript errors.

The error was being cause because the method was not relying in the keys set in the Entries, but the ones came from the contructor and from the field lookup.

The keys came from constructor and field lookup are not meant to be used in the client code, since they are internal.

This way, the error was solving by strict `get` method key type for consider only indexes (number) and Key originated from the Entries.

Example:

```typescript
interface Person {
   age: Integer
   name: string
}

const p: Record<Person> = // get record form somewhere

const age: Integer = p.get('age')
const name: string = p.get('name')

// @ts-expected-error This error was not being point out before
const nonExisitingKey = p.get('non-existing-key')
```
@robsdedude robsdedude self-requested a review November 14, 2022 09:18
Copy link
Member

@robsdedude robsdedude left a comment

Choose a reason for hiding this comment

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

🦐

@bigmontz bigmontz merged commit 1fe1471 into neo4j:5.0 Nov 15, 2022
@bigmontz bigmontz deleted the 5.x-fix-Record.get-typing branch November 15, 2022 11:18
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.

2 participants