{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/24322","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/24322/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/24322/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/24322/events","html_url":"https://github.com/Microsoft/TypeScript/issues/24322","id":325355385,"number":24322,"title":"Importing non-exported types","user":{"login":"Leandros","id":396475,"avatar_url":"https://avatars3.githubusercontent.com/u/396475?v=4","gravatar_id":"","url":"https://api.github.com/users/Leandros","html_url":"https://github.com/Leandros","followers_url":"https://api.github.com/users/Leandros/followers","following_url":"https://api.github.com/users/Leandros/following{/other_user}","gists_url":"https://api.github.com/users/Leandros/gists{/gist_id}","starred_url":"https://api.github.com/users/Leandros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Leandros/subscriptions","organizations_url":"https://api.github.com/users/Leandros/orgs","repos_url":"https://api.github.com/users/Leandros/repos","events_url":"https://api.github.com/users/Leandros/events{/privacy}","received_events_url":"https://api.github.com/users/Leandros/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-22T15:46:54Z","updated_at":"2018-05-22T16:10:21Z","closed_at":null,"author_association":"NONE","body":"\r\n\r\n## Search Terms\r\n\r\nimporting types, access private types, import non exported types\r\n\r\n\r\n## Suggestion\r\n\r\nConsider the following example:\r\n\r\n**types.ts:**\r\n\r\n```\r\nexport interface AnimalProps {\r\n  name: string;\r\n  age: number;\r\n}\r\nexport type Callback = (params: AnimalProps) => boolean;\r\n```\r\n\r\n**animal.ts:**\r\n```\r\nimport { AnimalProps, Callback } from './types';\r\n\r\nexport class Animal {\r\n  protected props: AnimalProps;\r\n  constructor(props: AnimalProps) {\r\n    this.props = props;\r\n  }\r\n  getProps(cb: Callback) {\r\n    cb(this.props);\r\n  }\r\n}\r\n```\r\n\r\n**index.ts:**\r\n```\r\nimport { Animal } from './animal';\r\n\r\nfunction main() {\r\n  const props/* : AnimalProps */ = { name: 'Linda', age: 8 };\r\n  const animal: Animal = new Animal(props);\r\n  console.log('animal:', animal);\r\n}\r\nmain();\r\n```\r\n\r\nYou can see that the `props` variable in `main` is untyped, and only type checked at the end, when actually passed to the constructor of `Animal`. \r\nI can't expose the `AnimalProps` to another module, since I have no way of accessing the type, due to a missing export in 'animal.ts'.\r\nI'd have to re-declare the `AnimalProps` inside `index.ts` and expose this. While this is simple in this example, it's more complex and often impossible in real-world projects, where `animal.ts` is, for example, the `index.ts` of a node module, hence `types.ts` not being available (example: https://github.com/prismagraphql/graphql-yoga/tree/master/src). \r\n\r\n## Use Cases\r\n\r\nCorrectly propagating the types throughout a code base, without having to do double the work to redefine all types.\r\n\r\n## Examples\r\n\r\nSee the above example. I encountered the case when trying to create a new `GraphQLServerLambda`, and wanting to expose the `LambdaProps` of it's constructor.\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n* [x] This wouldn't be a breaking change in existing TypeScript / JavaScript code\r\n* [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [x] This could be implemented without emitting different JS based on the types of the expressions\r\n* [x] This isn't a runtime feature (e.g. new expression-level syntax)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/391049272","html_url":"https://github.com/Microsoft/TypeScript/issues/24322#issuecomment-391049272","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/24322","id":391049272,"user":{"login":"andy-ms","id":19274678,"avatar_url":"https://avatars3.githubusercontent.com/u/19274678?v=4","gravatar_id":"","url":"https://api.github.com/users/andy-ms","html_url":"https://github.com/andy-ms","followers_url":"https://api.github.com/users/andy-ms/followers","following_url":"https://api.github.com/users/andy-ms/following{/other_user}","gists_url":"https://api.github.com/users/andy-ms/gists{/gist_id}","starred_url":"https://api.github.com/users/andy-ms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andy-ms/subscriptions","organizations_url":"https://api.github.com/users/andy-ms/orgs","repos_url":"https://api.github.com/users/andy-ms/repos","events_url":"https://api.github.com/users/andy-ms/events{/privacy}","received_events_url":"https://api.github.com/users/andy-ms/received_events","type":"User","site_admin":false},"created_at":"2018-05-22T16:10:21Z","updated_at":"2018-05-22T16:10:21Z","author_association":"CONTRIBUTOR","body":"You can always:\r\n* Declare `export { AnimalProps } from \"./types\";` in `animal.ts` and import that.\r\n* Just import from \"./types\" in `index.ts`.\r\n"}}
{"actor":{"display_login":"andy-ms"}}