30 isLoading,
31 isSuccess,
32 } = useQuery({
33 ...meetingQuery(token, uid as string), 34 });
35
36 const callPeer = async () => {
75
76 if (Cookies.get(key) === undefined && Cookies.get('refresh')) {
77 // refresh token is being called here because the token got expired on the client
78 await refreshToken(qc as QueryClient);79 }
80 return Cookies.get(key) as TState;
81 }
65 } else {
66 // use non-httpOnly cookies in dev env directly from Cookies lib
67 if (checkTokenType(value) && !del) {
68 Cookies.set(key, value as string);69 return value as TState;
70 }
71 if (del) {
106 const messagesWindowRef = React.useRef() as React.MutableRefObject<HTMLDivElement>;
107
108 const qc = useQueryClient();
109 const state = qc.getQueryState(['profile', loggedInUserUserName as string]);110
111 const fetchMessages = React.useCallback(
112 ({ channelVal, lastMessageID, ltOrGt }: FetchMessages) => {
100 const [noOfMessages, setNoOfMessages] = React.useState(10); // 6 is what fits in h-[60vh] and leaves room for infinite scroll
101 const { connected, toggleConnection } = useStreamContext();
102 const [showScrollDown, setShowScrollDown] = React.useState(false);
103 const profileData = useProfile(loggedInUserUserName as string) as Profile;104
105 const channelRef = React.useRef() as React.MutableRefObject<Channel<DefaultGenerics>>;
106 const messagesWindowRef = React.useRef() as React.MutableRefObject<HTMLDivElement>;
Type assertion is explicitly telling the compiler that we want to treat the entity as a different type. However, if we add a type assertion for a variable which is automatically inferred with the same type already then it is unnecessary to define the type explicitly.
Using a type assertion that does not change the type of an expression is unnecessary and should be avoided for a cleaner code.
// Types of 'foo' and 'bar' are already inferred as 'number', explicit type assertion in unnecessary
let foo = 3 as number;
let bar = <number>3;
function foobar(x: number): number {
return x!; // Type of 'x' is 'number' and is not 'null' or 'undefined'. Non-null assertion is unnecessary
}
type NewType = number;
let baz = 3 as NewType
let qux = <NewType>3
const foo = [1, 2] as const; // Using 'as const' enforces the array to be readonly
function foobar(x: number | undefined): number {
return x!;
}