Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • 10:15
    mitsos1os opened #46411
  • 10:00
    typescript-bot closed #46356
  • 09:43
    wuliqiangqiang opened #46410
  • 09:34
    JirkaDellOro opened #46409
  • 09:12
    JounQin opened #46408
  • 09:03
    remcohaszing edited #46407
  • 09:02
    remcohaszing opened #46407
  • 06:12
    AdrianAbramczyk opened #46406
  • 06:01
    JoshuaKGoldberg edited #46405
  • 06:00
    JoshuaKGoldberg edited #46405
  • 06:00
    JoshuaKGoldberg ready_for_review #46405
  • 05:39
    typescript-bot labeled #46405
  • 05:39
    JoshuaKGoldberg opened #46405
  • 01:33
    JoshuaKGoldberg synchronize #45836
  • 01:33
    JoshuaKGoldberg edited #45836
  • 01:32
    JoshuaKGoldberg synchronize #29374
  • 01:23
    JoshuaKGoldberg ready_for_review #45836
  • 01:22
    JoshuaKGoldberg edited #45836
  • 00:00
    typescript-bot closed #46360
  • Oct 17 21:04
    typescript-bot opened #46404
Keith Layne
My project won't build without it.
I think it's not terrible to enable for apps
thanks for looking into it though!
just got a feedback from octokit and they confirmed they require TS v4+ for this to work.
at least I have a plan B to workaround this problem
Archimedes Trajano

Can I rewrite this so that I don't have the const?

const theme: ITheme = { color: 'blue' }
export default theme;

I tried

export default : ITheme : {color: Blue}

and the following will disable type checks

export default  {color: Blue} as ITheme
1 reply
Tõnis Ostrat

heya. i'm working on a React project and i'm having trouble with typings.

let's say that i have the following component

export const FancyComponent = withFoo(withBar(withFizz((props) => {
  const { foo, bar, fizz } = props;

  // render logic

the HoC-provided prop types are automatically inferred but where (and how) should i define my own props? i want to, for example, pass a msg: string type in

N.S. Cutler
export enum RosterPosition {
  LW = 'Left Wing',
  RW = 'Right Wing',
  C = 'Center',
  LD = 'Left Defense',
  RD = 'Right Defense',
  G = 'Goalie'

export namespace RosterPosition {
  export const all = new Map<string, RosterPosition>()
  Object.keys(RosterPosition).forEach(x => {
    all.set(x, RosterPosition[x])

[LOG]: "LW" 
[LOG]: "RW" 
[LOG]: "C" 
[LOG]: "LD" 
[LOG]: "RD" 
[LOG]: "G" 
[LOG]: "all" // tf is this doing here??
N.S. Cutler
Filed an issue on this and was clued into the cause -- RosterPosition.all is exported and therefore merged into the Enum. Very puzzling behavior but now I see what's happening.
Jacob Madsen
Is it possible to define a method-decorator where the decorator can set a class method's arguments-type on the method in question? Naive example:
function methodDecorator<V>(v: V) {
  return <Name extends string>(
    target: { [N in Name]: (v: V) => any },
    propertyKey: Name,
    descriptor: PropertyDescriptor
  ) => {}

class A {
  someMethod(v) {} // Parameter 'v' implicitly has an 'any' type
Salathiel Genèse
Yes, it is possible
Salathiel Genèse
function Default<T>(defaultValue: T) {
    return function <O>(target: O, method: MethodWithParameter<O, T, 0>) {

type MethodWithParameter<T, PT, I extends number = number, K extends keyof T = keyof T> =
    K extends any ? T[K] extends (...args: any[]) => any ?
    Parameters<T[K]>[I] extends PT ? K : never
    : never : never;
The complete example, with variants, on TypeScript playground
Danilo Silva

Hello guys i have a question about NPM. I created a script to copy files into a dist folder. I'm doing a local private NPM library using verdaccio. But it just copy paste the files without transpile the typescript into JS. Can someone help me with what is missing?

"distribute": "set NODE_ENV=production&&babel src --out-dir dist --copy-files --ignore spec.js,test.js --source-maps"

set NODE_ENV=production&&babel doesn't look valid, unless you're using some other shell?
2 replies
if you're using bash or dash then NODE_ENV=production babel is what you want
no idea about getting babel to transpile, though.
Jacob Madsen
@SalathielGenese Thanks. What I am looking for is a way to get the parameter type from the decorator so it is not implicit any
Salathiel Genèse
@jacobmadsen - I tried that couple of years ago and failed. Because...
TypeScript (or rather the old decorator spec) resolve the decorator options before applying the decorator implementation
And not the other way around
If we move <O> to the decorator option level, and use it *as one of the decorator's options, that fine (because TypeScript can capture O type right there)
Otherwise, it is inferred to object pass that point and is object by the time the decorator implementation (as opp. to its option-function) get evaluated.
Salathiel Genèse


There technical idoms to better describe it, but I don't know them.

Jacob Madsen
@SalathielGenese Ok, it seems to be impossible as of now. Thank you
Salathiel Genèse
Any MappedType wizards here? I'm wondering if I could get rid of the as anys in this playground
4 replies
Salathiel Genèse
@Gregoor , what you're doing there iss beautiful
Salathiel Genèse
import { mapValues } from "lodash";

type LabeledRoutes = Record<string, string | readonly [string, readonly string[]]>;
type ActionedRoute<R extends LabeledRoutes[keyof LabeledRoutes]> = R extends string ? string : (params: Record<R[1][0], string>) => string;

const parameterizeRoutes = <R extends LabeledRoutes>(routes: R): { [RK in keyof R]: ActionedRoute<R[RK]> } =>
  mapValues(routes, (route) => {
  // ... removed for brevity
Andreas Herd
anyone one up for a TS challenge to solve this SO question:
https://stackoverflow.com/questions/69583908/type-guarding-the-2nd-argument-of-a-curried-function I've been banging my head for days now
Jacques Yakoub

Hello, I created a CLI tool (https://github.com/jy95/i18n-tools) and I want my code to be also consumable as an actual module so that others can reuse my logic in their code for example creating a GUI. Which build tool (rollup, parceljs, ...) could fit that need as simpler as possible ?

Thanks in advance

Keith Layne
You don't need a build tool for that - you can just publish an npm that has an executable for your CLI, and the programmatic API in the library.
Masood Ahmad
Hi, can anyone advise on ...spread and things in these highlighted lines? https://pastebin.mozilla.org/vr6ynGxv#L33,52
Masood Ahmad
What harm would I get by using it
using spread in this case
Keith Layne
Pro Tip™: use the playground, and make your examples not horribly broken, if you want help. Your case probably doesn't really need it, but all that stuff in a pastebin is distracting.
Keith Layne
Here's your example in playground @sircle:matrix.org
Your stuff is so broken that even though you're just asking for generalities it's hard to see how the embedded questions really relate to your example.
Keith Layne
  1. You always have to type props, pretty much. You can use any as a fallback.
  2. If libs don't have types, you can start with declare module 'whatever-lib'; and go from there. I'd personally avoid libs without types. If they're complex and don't have types, you're looking at a ton of work. If they're super simple and don't have types...you can probably do without them and implement the lib yourself.
  3. You control the linter. You decide what ruleset makes sense. If you agree with this rule, use it, if not, don't.
  4. This is useless. Browser console error implies an actual runtime error, which is unacceptable, but you don't describe what's actually wrong, and your example is so broken that it could be anything.
  5. I'm still not sure of what the main idea here is...you want to wrap a component without passing all the props? 🤷
Masood Ahmad
@keithlayne: thanks. my fellow dev was lazy i guess and didn't wanted to give types everytime and used ..spread for overlapping ones
Salathiel Genèse
DRY (Don't Repeat Yourself principle) vs. Laziness
Abdul Azeez
Hi am new here and also with TypeScript
all resources I have are not worth it pls if I can have some you know correct resources
Salathiel Genèse
TypeScript official website docs
Learn by practice
Don't suppose you understand: try it out and see for yourself
Copy/pasting don't help learning... Wrte it down yourself
Masood Ahmad
@SalathielGenese: agreed 100%
Masood Ahmad
@SalathielGenese: but if you see my case in https://pastebin.mozilla.org/vr6ynGxv#L33,52 if ..spread is not used, params will have to be repeated. And it seems that repetition should 'not' be avoided for good reasons as @keithlayne said.
Mayank Aggarwal
Soon will start sharing some dev related stuff🎉