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

Intersection type kills mapped types restriction #27143

Closed
luxalpa opened this issue Sep 17, 2018 · 3 comments
Closed

Intersection type kills mapped types restriction #27143

luxalpa opened this issue Sep 17, 2018 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@luxalpa
Copy link

luxalpa commented Sep 17, 2018

TypeScript Version: [email protected] (also happens in 2.7.2)
tested with unmodified tsconfig generated by tsc --init

Search Terms: intersection mapped types restrictions

Code

type locales = 'us' | 'jp' | 'nz'

type YZ = {
  [routeName: string]: {someRandomProperty?:string} & { // this does not throw the error!
  // [routeName: string]: {} & {        // this will throw the error!
  // [routeName: string]: {             // just like this!
  // [routeName: string]: undefined & { // or this!
    urls: {
      [P in locales]?: string;
    }
  }
}

let value: YZ = {
  'hello': {
    urls: {
      jp: 'dragon',
      ph: 'unknown'
    }
  }
};

Expected behavior:
There should be an error message along the lines of Type '{ jp: string; ph: string; }' is not assignable to type '{ us?: string | undefined; jp?: string | undefined; nz?: string | undefined; }'. Object literal may only specify known properties, and 'ph' does not exist in type '{ us?: string | undefined; jp?: string | undefined; nz?: string | undefined; }'

Actual behavior:
No error message is thrown :(

Playground Link:
Playground never shows the error message for some reason.

Related Issues:

#19927
#22255

@mattmccutchen
Copy link
Contributor

Duplicate of #13813.

@ahejlsberg ahejlsberg added the Duplicate An existing issue was already created label Sep 17, 2018
@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.

@jcalz
Copy link
Contributor

jcalz commented Nov 25, 2022

Looks like this has been fixed as of TS3.5.

This issue was closed.
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

5 participants