-
Notifications
You must be signed in to change notification settings - Fork 12.8k
@ts-ignore not included in .d.ts file when it's needed #38628
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
Comments
|
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
This is definitely broken. You just don't understand what I'm saying. |
@SephReed if you're not going to provide information to help me understand, what do you expect to happen? |
Setting the tag "Working as Intended" before asking for clarity doesn't inspire much faith. If you copy paste the code above and run |
I don't think it changes the answer, but what I believe @SephReed is saying is that they believe that when compiling a Of course they could simply write the code properly in the first place, instead of just ignoring errors: export function isProxied<TYPE extends object>(checkMe: TYPE | Sourcified<TYPE>): checkMe is ProxiedAny<TYPE>
{
return checkMe && typeof checkMe === "object" && "_proxied" in checkMe;
} |
I haven't heard anything that contradicted my initial understanding of the issue.
It's not a magic spell that will cause all downstream effects of that error to go away. We don't know what your intent of These were exactly the kinds of things we cautioned would be limitations of |
I know you aren't working with my codebase, so you can't know this, but If I import a I understand that I'm working on edge cases, and that it's really just a problem for me. But please don't say that |
In the end, I have made very, very rare use of It's a problem solved for me. If you guys don't care that |
ts-ignore comments are stripped from declaration files: microsoft/TypeScript#38628 It'd be possible to use some kind of codegen to add them back in, but it's easier and more correct to define what we need explicitly from the sequelize type definitions.
ts-ignore comments are stripped from declaration files: microsoft/TypeScript#38628 It'd be possible to use some kind of codegen to add them back in, but it's easier and more correct to define what we need explicitly from the sequelize type definitions.
ts-ignore comments are stripped from declaration files: microsoft/TypeScript#38628 It'd be possible to use some kind of codegen to add them back in, but it's easier and more correct to define what we need explicitly from the sequelize type definitions.
@RyanCavanaugh this decision makes sense. I'm wondering though, what should library authors do that want to allow users of multiple typescript versions? Specifically, when there's a nice-to-have but non-essential feature. Example using the // @ts-ignore
type Push_ts4<A extends unknown[], B> = [...A, B];
type VariadicTuplesPrefixesSupported = Push_ts4<[1, 2], 3> extends { length: 3 } ? "yes" : "no";
type Push<A extends unknown[], B> = VariadicTuplesPrefixesSupported extends "yes"
? Push_ts4<A, B>
: Array<A[number] | B>; The idea is that in recent typescript versions, I tested this by installing a lower typescript version and compiling, which worked because the source code has the ts-ignore. But I forgot that it wouldn't end up in the declaration files that users actually use, and now I've got a bug report of the library causing compilation errors for old typescript versions: mmkal/handy-redis#250 What would you suggest I do here to un-break the downstream users, short of |
@mmkal downlevel-dts and See Ryans comment: #41685 (comment) |
this sounds absurd to me
doesn't that make it completely useless then for packages intended to be imported downstream? i often need it'd be like if type casts were stripped. how is it at all intentional behavior to change the code at compiletime to emit invalid |
Can’t all those be worked around with an intersection? |
@andrewbranch wow you're right, thanks! however i still think it's an issue that the ignore comments behave this way. is there some reason behind it that i'm missing? regardless, i think the dangers of
afaik nowhere in the documentation does it warn about this extremely dangerous behavior. especially for people publishing packages these errors will go undetected by any of their testing and will only be picked up by someone downstream trying to import them, so i'm not surprised people are misapprehending it is it safe to say that |
I’m open to hearing feedback about how
Not quite—it’s perfectly “safe” to use one of those in implementation code that doesn’t contribute to the type signature of any globals or module exports. It’s only bad news when the comment applies to something that will necessarily be copied to the declaration files, like a return type annotation of an exported function or something. But you may be right that the docs should do more to warn library authors about this. |
i agree, i was thinking about this the other day actually, what if there was a compiler option to fallback to
would it be possible to have an error when using |
The use case I have for I think this use cases is legitimate as it is not an attempt to silence an error which will propagate and break things. It's working around a limitation in the language (in this case: that we don't have temporary type variables, but it could be something else) in a way that is, to the contrary, safer than the alternative which would be to not put a type constraint at all on this parameter. I used this pattern twice in the same library, you will find extracts bellow but I also want to comment on the developer experience related to this issue. Today I realised I was forced to compile my type-level libraries in order to make them compatible with TS Playground (and maybe other tools which don't seem to be willing to import The instances in which I used the pattern: type Pipe<
Args extends $Ts[0]['constraints'],
$Ts extends [Result] extends [never] ? never : Composition,
// @ts-ignore: prevent users from messing with it
Result extends never = _Pipe<Args, $Ts>
// -------------
> = Result
I did something similar in this other type: in order to not repeat interface $Match<
Cases extends Case[] & CheckCases<Model, Cases>,
Model extends CheckFallThrough<Model, Cases> = never,
// @ts-ignore: prevent users from messing with it
// vvvvvvvvvvvvv
Otherwise extends never = GetOtherwise<Cases>
> extends Type<1> {
type: _Match<this[A], Cases>
constraints: [
[Otherwise] extends [never] ? unknown
: Otherwise extends _never ? unknown
: Otherwise extends Type ? Otherwise['constraints']
: unknown
]
} In this case I was able to rewrite it this way because interface $Match<
Cases extends Case[] & CheckCases<Model, Cases>,
Model extends CheckFallThrough<Model, Cases> = never,
> extends Type<1> {
type: _Match<this[A], Cases>
constraints: [
[this['__Otherwise']] extends [never] ? unknown
: this['__Otherwise'] extends _never ? unknown
: this['__Otherwise'] extends Type ? this['__Otherwise']['constraints']
: unknown
]
__Otherwise: GetOtherwise<Cases>
} |
I just find out that if you use a |
interesting. looks like |
JSDoc is used in tooltips. Can we rely on this behaviour though? Is this an unforeseen conflict or did someone think "gee, if you use that syntax you really mean to keep that Because if it gets "fixed" under our feet it will silently break users. |
preserving
|
- @ts-* comments are meaningful comments, but typescript does not preserve them 🙃🙄 - re-implemented 779cddf as build plugin - microsoft/TypeScript#38628 - microsoft/TypeScript#38628 (comment) Signed-off-by: Lexus Drumgold <[email protected]>
If I add a Funny thing, ChatGPT suggests you use |
At the moment, since `@ts-expect-error` [doesn't apply][1] to type definitions, we get a downstream compilation error: ``` TS2416: Property 'addModule' in type 'BaseTheme' is not assignable to the same property in base type 'Theme'. Type '(name: string) => unknown' is not assignable to type '{ (name: "clipboard"): Clipboard; (name: "keyboard"): Keyboard; (name: "uploader"): Uploader; (name: "history"): History; (name: "selection"): Selection; (name: string): unknown; }'. Type '{}' is missing the following properties from type 'Clipboard': matchers, addMatcher, convert, convertHTML, and 8 more. 10 addModule(name: string): unknown; ``` This change updates the `Base` class to have the same signature as for `addModule()` as its parent class. [1]: microsoft/TypeScript#38628
At the moment, since `@ts-expect-error` [doesn't apply][1] to type definitions, we get a downstream compilation error: ``` TS2416: Property 'addModule' in type 'BaseTheme' is not assignable to the same property in base type 'Theme'. Type '(name: string) => unknown' is not assignable to type '{ (name: "clipboard"): Clipboard; (name: "keyboard"): Keyboard; (name: "uploader"): Uploader; (name: "history"): History; (name: "selection"): Selection; (name: string): unknown; }'. Type '{}' is missing the following properties from type 'Clipboard': matchers, addMatcher, convert, convertHTML, and 8 more. 10 addModule(name: string): unknown; ``` This change updates the `Base` class to have the same signature as for `addModule()` as its parent class. [1]: microsoft/TypeScript#38628
At the moment, since `@ts-expect-error` [doesn't apply][1] to type definitions, we get a downstream compilation error: ``` TS2416: Property 'listeners' in type 'Emitter' is not assignable to the same property in base type 'EventEmitter<string, any>'. Type 'Record<string, { node: Node; handler: Function; }[]>' is not assignable to type '<T extends string>(event: T) => ((...args: any[]) => void)[]'. Type 'Record<string, { node: Node; handler: Function; }[]>' provides no match for the signature '<T extends string>(event: T): ((...args: any[]) => void)[]'. 19 listeners: Record<string, { ``` This change removes the clash by renaming the internal variable. Note that, since `listeners` is `public`, this is technically breaking. [1]: microsoft/TypeScript#38628
At the moment, since `@ts-expect-error` [doesn't apply][1] to type definitions, we get a downstream compilation error: ``` TS2416: Property 'addModule' in type 'BaseTheme' is not assignable to the same property in base type 'Theme'. Type '(name: string) => unknown' is not assignable to type '{ (name: "clipboard"): Clipboard; (name: "keyboard"): Keyboard; (name: "uploader"): Uploader; (name: "history"): History; (name: "selection"): Selection; (name: string): unknown; }'. Type '{}' is missing the following properties from type 'Clipboard': matchers, addMatcher, convert, convertHTML, and 8 more. 10 addModule(name: string): unknown; ``` This change updates the `Base` class to have the same signature as for `addModule()` as its parent class. [1]: microsoft/TypeScript#38628
At the moment, since `@ts-expect-error` [doesn't apply][1] to type definitions, we get a downstream compilation error: ``` TS2416: Property 'addModule' in type 'BaseTheme' is not assignable to the same property in base type 'Theme'. Type '(name: string) => unknown' is not assignable to type '{ (name: "clipboard"): Clipboard; (name: "keyboard"): Keyboard; (name: "uploader"): Uploader; (name: "history"): History; (name: "selection"): Selection; (name: string): unknown; }'. Type '{}' is missing the following properties from type 'Clipboard': matchers, addMatcher, convert, convertHTML, and 8 more. 10 addModule(name: string): unknown; ``` This change updates the `Base` class to have the same signature as for `addModule()` as its parent class. [1]: microsoft/TypeScript#38628
Not being able to propagate @ts-ignore and so on to the generated .d.ts file makes it super annoying to deal with the kind of bug that you can see in the following issue (typescript works fine, but d.ts breaks). Right now I'm trying to expose some shared zod type definitions to internal libs and i'd rather not use skipLibCheck. Being able to just add a few @ts-ignores so i can make my d.ts file work as a workaround would be much better. |
Same problem here. I thought Here is an example: // Types ----------------------------------------------------------------------
interface BaseIssue<TInput> {
type: string;
input: TInput;
}
interface BaseSchema<TOutput, TIssue extends BaseIssue<unknown>> {
type: string;
_run: (input: unknown) => TOutput;
output: TOutput;
issue: TIssue;
}
interface StringIssue extends BaseIssue<string> {
type: 'string';
}
interface StringSchema extends BaseSchema<string, StringIssue> {
type: 'string';
}
interface NumberIssue extends BaseIssue<number> {
type: 'number';
}
interface NumberSchema extends BaseSchema<number, NumberIssue> {
type: 'number';
}
interface LazySchema<TSchema extends BaseSchema<unknown, BaseIssue<unknown>>>
extends BaseSchema<TSchema['output'], TSchema['issue']> {
type: 'lazy';
}
// Implementation ------------------------------------------------------------
// @ts-expect-error
type MaybeLazyString = StringSchema | LazySchema<MaybeLazyString>;
type IsMaybeLazyString<
TSchema extends BaseSchema<unknown, BaseIssue<unknown>>,
> = TSchema extends MaybeLazyString ? true : false;
// Tests ---------------------------------------------------------------------
type Test1 = IsMaybeLazyString<LazySchema<LazySchema<StringSchema>>>; // -> true
type Test2 = IsMaybeLazyString<NumberSchema>; // -> false |
TypeScript Version: (version check command not supplied)
Search Terms:
@ts-ignore .d.ts
Code
For reasons within my codebase, the following code absolutely necessitates
// @ts-ignore
in order to disable an issue in whichProxiedAny<TYPE extends object>
only takes objects for TYPE. Without this line, I get the error:Type 'TYPE' does not satisfy the constraint 'object'
Expected behavior:
When compiling, I would expect to find this //@ts-ignore included with the
.d.ts
file.Actual behavior:

The .d.ts file is broken:
Alternatives:
Maybe
arg is TYPE
should be able to do something likearg as unknown is TYPE
in order to get around this issue. I'm checking if it's an object, and need a way to tell Typescript so.The text was updated successfully, but these errors were encountered: