-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
Deprecation expectations #51
Comments
Makes sense to me as long as we clearly document to not use it for unambiguous situations (no overloads, for example). |
I already have some code locally to cover this because I experimented how feasible this would be to implement. It turned out to be pretty straight forward. Only have to finish it and then it should be ready. @sindresorhus Can you clarify the overload thing? The |
I implemented it locally, but was wondering if we should do this for properties as well. interface Unicorn {
/**
* @deprecated
*/
readonly property: string;
}
const unicorn: Unicorn = {
property: 'unicorn'
};
expectDeprecated(unicorn.property); Should it check this as well? Or should we currently only allow |
In the TS AST this is called a If we want to do this, are there other things that might be marked as deprecated? An entire interface for instance? /**
* @deprecated
*/
interface Unicorn {
readonly property: string;
} Not sure if this is possible. Might be opening pandora's box here 😂. I would be fine to start with |
FWIW, I cheated and lifted TSLint's deprecation-sniffing implementation: Which, IIRC, finds deprecations for properties. |
I just want to make sure users don't create moot assertions, like #51 (comment), where nothing else could affect it, so there's no reason to test whether it's deprecated.
Yes, we should check properties too. |
This is what I have right now as a test for import {expectDeprecated} from '../../../..';
import concat, {Unicorn, Options} from '.';
// Methods
expectDeprecated(concat('foo', 'bar'));
expectDeprecated(concat(1, 2));
//=> Expected `(foo: number, bar: number): number` to be marked as `@deprecated`
// Properties
const options: Options = {
separator: ',',
delimiter: '/'
};
expectDeprecated(options.separator);
expectDeprecated(options.delimiter);
//=> Expected `Options.delimiter` to be marked as `@deprecated`
// ENUM
expectDeprecated(Unicorn.UNICORN);
expectDeprecated(Unicorn.RAINBOW);
//=> Expected `Unicorn.RAINBOW` to be marked as `@deprecated` Works the same for I was in doubt if you should be able to validate the deprecation message. const enum Unicorn {
/**
* @deprecated - Use Rainbow instead
*/
UNICORN = '🦄',
RAINBOW = '🌈'
}
expectDeprecated(Unicorn.UNICORN, 'Use Rainbow instead'); But decided not to (for now) as I wasn't sure if it was useful. |
I don't know what the definition for And for methods, too. (Which I didn't test, 'cause I just lifted the TSLint deprecation sniffer.) |
Sorry, didn't provide the concat definition. It's an overload declare const concat: {
/**
* @deprecated
*/
(foo: string, bar: string): string;
(foo: number, bar: number): number;
};
export default concat; Thanks for linking your tests. I was looking for them but couldn't find them. |
In RxJS, we have a significant number of overload signatures that are deprecated and seemingly unrelated changes to overload signatures and effected false positives for deprecations.
It would be nice to be able to add tests to ensure that deprecations as behaving as they should. To this end, I've added a TSLint rule that can be used with dtslint to test our deprecations.
The tests will look something like this:
Would you be open to adding two additional expectations to this package so that the presence and absence of deprecations could be tested?
The text was updated successfully, but these errors were encountered: