-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
export type * from 'somewhere'
#48508
Comments
Related: #36966 |
@andrewbranch any concerns? |
Hm, yeah, kind of. If this syntax were allowed, it wouldnβt do what the suggestion says (βre-export all types (and only types)β) because thatβs not how type-only imports/exports work. Consider named exports as an analogy: export type { someValue } from "foo" While not particularly useful, this is allowed. When imported from here, The way to think about type-only imports and exports is that they have identical resolution semantics to their non-type-only counterparts, but impose restrictions on any references to them. So import { one, two, three, four, TypeOne, TypeTwo, TypeThree } from "./foo-reexporter"
one; // ok
two; // ok
three; // ok
four; // Error: 'four' cannot be used as a value because it was exported using 'export type'.
type T1 = TypeOne; // ok
// ... It sounds like @trusktr would have expected the import of |
@trusktr given the above, would that still fit your use case? |
I ran into this just now, in a slightly different way:
export type T1 = // ...
import { T1 } from './foo';
export function f(arg: T1): boolean {
// ...
}
export * from './foo';
export * from './bar'; This crashes at runtime for a slightly different reason -- there is no |
While itβs true that this feature request would get around that, itβs not a bugβa module |
@andrewbranch Is that documented anywhere? I haven't heard of this before, and I've seen standalone |
I donβt know if thatβs explicitly stated anywhere, itβs just kind of a natural consequence of what declaration files are. When you compile a import * as types from "type-fest"
console.log(types) There is no error here, and yet this will crash at runtime, because all the module .d.ts files in type-fest imply that there are modules, exporting nothing, all over that package, where there are none. (Also, any usage of type-fest with |
@andrewbranch type only external module would address a lot of my use cases where i abuse rollup to bundle generated typedefinitions for the correct bundels. i could avoid that and create a typescript file .ts that generates only the needed declarations directly matching the output as i always generate the output from the list of entrypoints i get bundels for each entrypoint so every entrypoint needs exact the same type only .d.ts files the entrypoints are most of the time and that needs to be the only supported case files that contain only import statements and export statements when typescript would have a sense of a type only module it could generate the correct .d.ts files for that bundels via a .ts or .d.ts file that does type only reExports that also would save a lot of tsconfig hustle. by the way i invented type only files via checkJs allowJs containing jsdoc annotated import('./myType').TypeName and building that it is my hacky workaround for that .js files can easy get excluded in typescript compile steps as also they can get easy compiled with emitDeclaration only which is in fact a external typeOnly module. (declaration) the typescript project can this way stay untouched and behave like normal while i have outside of it a referencing project that only builds the .js entrypoints typedeclarations using the types from the typescript project. sure i could also use .ts files but that always produces wirred quirks and needs more config. Also the .js method worked before there was a type only import. and makes clear that the file is only about types. as it contains no real code that would get bundled or compiled by typescript. |
In my case yeah. I didn't think that far into it: I had a bunch of |
I would also welcome an In my opinion, the data are received and stored in an object. the corresponding class file could be different in the different service. most of the times the class differs a little bit, because it provides only required values and casts date stings to date objects. that is only one example. I believe there are more. I think TS should be flexible enough to deal with different teams approaches. |
Duplicate of #37238, I'm cross-posting my use-case:
|
Iβm going to go ahead and close this as a duplicate of #37238 and redirect any further conversation there as that one has a lot more eyes on it. Thanks @nicolo-ribaudo. |
Suggestion
π Search Terms
typescript export type star
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
Just like
export * from 'foo'
, we should be able toexport type * from 'foo'
to re-export all types (and only types).π Motivating Example
This is useful in cases where we re-export certain things for runtime, but still wish to re-export all types:
π» Use Cases
βοΈ
The text was updated successfully, but these errors were encountered: