Skip to content

Fix array handling in SchemaOf type - #1169

Merged
jquense merged 1 commit into
jquense:masterfrom
chasecaleb:fix-schemaof-type
Dec 10, 2020
Merged

Fix array handling in SchemaOf type#1169
jquense merged 1 commit into
jquense:masterfrom
chasecaleb:fix-schemaof-type

Conversation

@chasecaleb

Copy link
Copy Markdown
Contributor
  1. Move array before object so that inference works correctly
  2. Include Lazy as part of ArraySchema's generic, to match the class definition

Here's a quick snippet that illustrates why 1 is necessary:

export const array: Array<string> = ["abc"];
// Valid - an Array is a Record (note: AnyObject is a type alias for Record<string, any>)
export const record: Record<string, any> = array;
// Doesn't compile
export const anotherArray: Array<string> = record;

By the way, I noticed that eslint isn't checking the $ExpectType comments in test/type.ts... I investigated it for a little bit, but ran into more problems so I gave up. You need to add --ext=.ts,.js when running eslint to make sure it checks the ts file, but then eslint started to give parser errors and I lost motivation. That's my excuse for not adding tests, sorry about that.

- Move array before object so that inference works correctly
- Include lazy as part of array type, to match the class definition
@jquense
jquense merged commit e785e1a into jquense:master Dec 10, 2020
@jquense

jquense commented Dec 10, 2020

Copy link
Copy Markdown
Owner

huh TIL. thanks!

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