!xfqwqigUlAuUTEIPwA:matrix.org

TypeScript

1163 Members
A superset of JavaScript that compiles to clean JavaScript output. https://www.typescriptlang.org/36 Servers

Load older messages


SenderMessageTime
3 Jul 2020
@rhussmann:matrix.orgrhussmann I may be confusing things here, as I don't know what MutableRefObject is. 19:34:16
@gitter_rraziel:matrix.orgRaziel (Gitter) Ah I thought you meant doing theMutableRef!.method, nvm then 19:34:31
@gitter_rraziel:matrix.orgRaziel (Gitter)Anyway ! should be avoided just like casts19:35:05
@gitter_bsdis:matrix.orgbsdis (Gitter) I am doing this: let date: Date = moment(e.currentTarget.value).format(dateformat); but that gives error: Type 'string' is not assignable to type 'Date'. Why? 21:44:19
@gitter_ceremonious:matrix.orgMayhul Arora (Gitter) joined the room.21:48:55
@gitter_ceremonious:matrix.orgMayhul Arora (Gitter)

Anyone have experience using opaque types with Typescripts records?

The following code is giving me the following error: "Element implicitly has an 'any' type because expression of type 'UserID' can't be used to index type 'Record<UserID, Chat>'."

type UserID = string & { readonly _: unique symbol };

interface Chat {
  name: string
}

type AllChats = Record<UserID, Chat>;

const test: AllChats = {}
const userID = "ads" as UserID;

test[userID] = {
  name: "my chat"
}
21:49:02
@gitter_rraziel:matrix.orgRaziel (Gitter) @bsdis because it formats a date to a specific string representation, what are you trying to do exactly? 21:49:24
@gitter_bsdis:matrix.orgbsdis (Gitter) @rraziel I want to format a string into a date object given a specific format 21:50:54
@gitter_rraziel:matrix.orgRaziel (Gitter) @ceremonious I assume you need to do some if (isStringUserId(userID)) { test[userId].. 21:50:57
@gitter_rraziel:matrix.orgRaziel (Gitter) (but yeah, you're saying it's a string with some extra property/method so it shouldn't be an issue I think) 21:51:46
@gitter_rraziel:matrix.orgRaziel (Gitter) @bsdis a date object doesn't have a format 21:53:06
@gitter_rraziel:matrix.orgRaziel (Gitter) Or you mean you want to parse a date that's in a specific format to a Date object? 21:53:33
@gitter_bsdis:matrix.orgbsdis (Gitter)i tried this also let date: Date = moment(e.currentTarget.value, dateformat); Do you know how to just return a Date object ?21:53:42
@gitter_bsdis:matrix.orgbsdis (Gitter) "Or you mean you want to parse a date that's in a specific format to a Date object?" <--- yes exactly 21:54:03
@gitter_rraziel:matrix.orgRaziel (Gitter) Ah then it's just toDate() (iirc) 21:54:46
@gitter_bsdis:matrix.orgbsdis (Gitter)aha21:55:20
@gitter_bsdis:matrix.orgbsdis (Gitter)thx21:55:22
@gitter_bsdis:matrix.orgbsdis (Gitter)

Hmm is this wrong?

          onBlur={(e: React.FormEvent<HTMLInputElement>) => {
            try {
              let date: Date = moment(
                e.currentTarget.value,
                dateformat
              ).toDate();
              setChosenDate(date);
              setErrorClass("");
            } catch (e) {
              setErrorClass("errorborder");
            }
          }}

It gives me Missing catch or finally clause. But I have a catch clause

21:57:16
@gitter_rraziel:matrix.orgRaziel (Gitter)Hm should those first and last { } be there?22:00:07
@gitter_rraziel:matrix.orgRaziel (Gitter)But the try/catch itself looks ok22:00:42
@gitter_bsdis:matrix.orgbsdis (Gitter) @rraziel ok that was apparantly an old error 22:07:46
@gitter_bsdis:matrix.orgbsdis (Gitter) I made the implementation now: https://codesandbox.io/s/sweet-mirzakhani-3vvsf But the problem is that if i use defaultValue={moment(chosenDate).format(dateformat)} then the textfield does not change when i change the calendar, and if i instead do value={moment(chosenDate).format(dateformat)} then I cannot update the textfield manually. What to do then? 22:10:28
@gitter_rraziel:matrix.orgRaziel (Gitter) Can't help much with React 22:13:37
4 Jul 2020
@gitter_janusqa:matrix.orgjanusqa (Gitter) joined the room.00:26:39
@gitter_janusqa:matrix.orgjanusqa (Gitter)

Hi can anyone help in solving this error?

type A = {
   a: string;
   b: number;
   c: boolean
};

let B: A[];

B = [
   {
      a: "ccc",
      b: 1,
      c: true
   },
   {
      a: "aaa",
      b: 1,
      c: true
   },
   {
      a: "bbb",
      b: 1,
      c: true
   }
];


const [key, setKey] = useState({
   keyA: 'a' 
});

const someFunc = function someFunc() {
   console.log(B);
   B.sort((a, b) => a[keys.keyA].localeCompare(b[keys.keyA], 'en', { ignorePunctuation: true }));
   console.log(B);
}

error

Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'A'.(7053)
00:26:40
@pedroexpedito:matrix.orgpedroexpedito joined the room.02:28:01
@jangid:matrix.orgjangid joined the room.03:08:03
@richard:perthchat.orgrichard 09:03:44
@pyjammas:matrix.orgpyjammas joined the room.09:10:13
@gitter_bsdis:matrix.orgbsdis (Gitter) Hi. why is this exception not catching parse error? https://dpaste.org/NieG 09:35:42

There are no newer messages yet.


Back to Room List