Learn
infer and
extends and you will accept all the downsides being zen from the height of your highly well typed codebase. If you don't find the following compelling:
type IsParameter = Part extends `[${infer ParamName}]` ? ParamName : never;
type FilteredParts = Path extends `${infer PartA}/${infer PartB}`
? IsParameter | FilteredParts
: IsParameter;
type ParamValue = Key extends `...${infer Anything}` ? string[] : number;
type RemovePrefixDots = Key extends `...${infer Name}` ? Name : Key;
type Params = {
[Key in FilteredParts as RemovePrefixDots]: ParamValue;
};
type CallbackFn = (req: { params: Params }) => void;
function get(path: Path, callback: CallbackFn) {
// TODO: implement
}
get(
'/purchase/[shopid]/[itemid]/args/[...args]',
({ params }) => {
params.shopid // number
params.itemid // number
params.args // string[]
},
);
(
https://lihautan.com/extract-parameters-type-from-string-lit...)
then you probably don't need TypeScript, or types in general. And that is fine.
As to the points:
(i) 99.99% of everything is being developed by someone else in our current stack, but here comes the benefits of open source: don't like how a project is going? fork it and maintain it yourself;
(ii) If you don't use a NPM package with the last release older than 2014 (and why would you given your (i)st fear), chances are pretty high (95%+) the library is written directly in TypeScript or there is a DefinitelyTyped package with the types;
(iii) Type errors, those that come directly from TypeScript, are pretty straightforward (was expecting X, you passed Y);
(iv) Yes, TypeScript should have never been written in an interpreted language, but what were the options in 2012: C? C++? Maybe some day in the unspecified future, we will have a Rust/compiled language implementation with microsecond transpilation time.