Skip to content

Return value with unknown key is not restricted #50173

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

Closed
loynoir opened this issue Aug 4, 2022 · 2 comments
Closed

Return value with unknown key is not restricted #50173

loynoir opened this issue Aug 4, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@loynoir
Copy link

loynoir commented Aug 4, 2022

Bug Report

🔎 Search Terms

return value unknown key

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions Version 4.7.4__ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

Playground link with relevant code

💻 Code

type FooEnv = {
  FOO: string;
};

type BarEnv = {
  BAR: string;
};

type EnvMap = {
  foo: FooEnv;
  bar: BarEnv;
};

function createFoobar<T extends keyof EnvMap>(
  _name: T,
  fn: (ctx: {}) => { env: EnvMap[T] }
) {
  return fn({});
}

createFoobar("foo", () => {
  return {
    env: {
      FOO: "",
      UNKNOWN: 42,
    },
  };
});

Config

{
  "exclude": ["dist"],
  "extends": "@tsconfig/node16-strictest-esm/tsconfig.json",
  "compilerOptions": {
    "noEmit": true
  }
}

🙁 Actual behavior

No error

🙂 Expected behavior

createFoobar("foo", () => {
  return {
    env: {
      FOO: "",
      // @ts-expect-error
      UNKNOWN: 42,
    },
  };
});
Type '{ FOO: string; UNKNOWN: number; }' is not assignable to type 'FooEnv'. 
Object literal may only specify known properties, 
and 'UNKNOWN' does not exist in type 'FooEnv'.
@jcalz
Copy link
Contributor

jcalz commented Aug 4, 2022

Duplicate of #241, most recent duplicate at #50064

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 4, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants