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

fix: allow to push single items in arrays #182

Merged
merged 8 commits into from
Nov 1, 2023

Conversation

Yarmeli
Copy link
Contributor

@Yarmeli Yarmeli commented Oct 24, 2023

Implemented a fix for #181

@arthurfiorette
Copy link
Owner

Can you add some tests?

@Yarmeli
Copy link
Contributor Author

Yarmeli commented Oct 31, 2023

I added some tests, let me know your thoughts on them 😄

Also, I noticed that some tests that should fail, don't really fail, for example:

// literal.test-d.ts

expectAssignable<Model>({
  id: 0,
  simple: 1,
  optional: 2,
  list: [3]
}); // ✅ it passes correctly

// copy the above code and replace the method with 'expectNotAssignable'
expectNotAssignable<Model>({
  id: 0,
  simple: 1,
  optional: 2,
  list: [3]
}); // ❌ the test passes but it should fail because this can be assigned to Model

My understanding is that this happens because of how arrays are handled in the tsd package. I opened an issue in there

@arthurfiorette
Copy link
Owner

arthurfiorette commented Nov 1, 2023

Should I wait for this fix at tsd?

@arthurfiorette arthurfiorette added the enhancement New feature or request label Nov 1, 2023
@arthurfiorette arthurfiorette self-assigned this Nov 1, 2023
@Yarmeli
Copy link
Contributor Author

Yarmeli commented Nov 1, 2023

I don't think it would make much of a difference waiting for the tsd fix/suggestion on how to handle arrays since that currently affects new and old tests.

I can open a new issue to improve the tests depending on what the fix is for that issue

@arthurfiorette
Copy link
Owner

@Yarmeli ok. CI is still failing

test/types/mongo.test-d.ts Outdated Show resolved Hide resolved
assets/namespace.d.ts Outdated Show resolved Hide resolved
assets/namespace.d.ts Outdated Show resolved Hide resolved
@arthurfiorette
Copy link
Owner

Can you run pnpm prettier --write . and commit the changes

@Yarmeli
Copy link
Contributor Author

Yarmeli commented Nov 1, 2023

Hopefully, this should have worked 🤞

I am having issues on my local machine with prettier not being able to find prettier plugin modules for this repo 😞

@arthurfiorette arthurfiorette merged commit ef5aae7 into arthurfiorette:main Nov 1, 2023
2 checks passed
@arthurfiorette arthurfiorette linked an issue Nov 1, 2023 that may be closed by this pull request
2 tasks
@mrazauskas
Copy link

mrazauskas commented Nov 17, 2023

@Yarmeli Just a quick note. Might be you saw already, last week I released TSTyche, a fresh type testing tool. This is the one I promised in tsdjs/tsd#199

Repo: https://github.com/tstyche/tstyche
Documentation: https://tstyche.org


Before we talked about widening of inferred types. I explained it in documentation. This is how TypeScript works and that is for good reason. But with TSTyche you can avoid widening in your type tests by comparing two types:

import { expect } from "tstyche";

interface Options {
  locale?: Array<"en" | "de">;
  root?: string;
}

expect<Options>().type.toBeAssignable<{
  locale: ["en", "de"];
}>();

expect<Options>().type.toBeAssignable<{
  root: string;
}>();

Also with TSTyche you can test types on specific versions of TypeScript: tstyche --target 4.8,5.0,latest. Very useful for complex generic types. Give it a try (;


PS Commenting here, because I don’t feel like this is anyhow related with tsd.

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 this pull request may close these issues.

Issues with pushing new values to a JSON object array
3 participants