Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Typescript: randEmail, randFirstName, and randLastName (and likely more) return type string[] when no options present #74

Closed
kpervin opened this issue Jan 19, 2022 · 1 comment

Comments

@kpervin
Copy link

kpervin commented Jan 19, 2022

Is this a regression?

No

Description

Expected Behavior:

The following

const fields = {
    contactEmail: randEmail(),
    contactFirstName: randFirstName(),
    contactLastName: randLastName(),
  };

should report return values of

const fields = {
    contactEmail: string,
    contactFirstName: string,
    contactLastName: string
  };

Current behavior:

The above functions result in reporting

const fields = {
    contactEmail: string[],
    contactFirstName: string[],
    contactLastName: string[]
  };

Suggested fix:

declare function rand*<Options extends FakeOptions = undefined>(options?: Options): Options["length"] extends number ? string[] : string;

instead of

declare function rand*<Options extends FakeOptions>(options?: Options): Options["length"] extends number ? string[] : string;

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

The issue simply has to do with that the type seems to favor the left-hand side of the type argument.

Please provide the environment you discovered this bug in

tsconfig: {
  "compilerOptions": {
    "module": "commonjs",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "es2017",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "esModuleInterop": true
  }
}

Webstorm 2021.3
VSCode 1.63.2

Anything else?

For some reason, the error does not present itself when run in Code Sandbox with the same tsconfig. However, it has presented itself in two IDE with the above tsconfig.

Do you want to create a pull request?

No

@NetanelBasal
Copy link
Member

image

@ngneat ngneat locked and limited conversation to collaborators Jan 19, 2022
@NetanelBasal NetanelBasal converted this issue into discussion #76 Jan 19, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants