nexxel
nexxel
Explore posts from servers
TTCTheo's Typesafe Cult
Created by nexxel on 4/23/2023 in #questions
how to override extended eslint config
hi i am using antfu's eslint config (https://github.com/antfu/eslint-config). here's my .eslintrc.cjs
process.env.ESLINT_TSCONFIG = 'tsconfig.json'

/** @type {import("eslint").Linter.Config} */
const config = {
root: true,
extends: '@antfu',
}

module.exports = config
process.env.ESLINT_TSCONFIG = 'tsconfig.json'

/** @type {import("eslint").Linter.Config} */
const config = {
root: true,
extends: '@antfu',
}

module.exports = config
now i want to override a rule to use double quotes instead of single quotes. the readme says i can override it by adding it to a rules field. so i added it like this:
const config = {
root: true,
extends: '@antfu',
rules: {
quotes: ['error', 'double'],
},
}
const config = {
root: true,
extends: '@antfu',
rules: {
quotes: ['error', 'double'],
},
}
but instead of overriding, its actually enforcing both the rules. https://this-vegetable.is-from.space/Code_53HG4zHeSp.gif
24 replies
TTCTheo's Typesafe Cult
Created by nexxel on 4/8/2023 in #questions
test
test
7 replies
SIASapphire - Imagine a framework
Created by nexxel on 3/18/2023 in #sapphire-support
How do I listen for reactions on all messages in a channel?
doing discord bot dev after a long time. i wanted to listen for message reactions on every message in a channel and run a db query in the run function. but for some reason i can't even get a simple log to work rn. what am i doing wrong here?
// src/listeners/reaction.ts

import { ApplyOptions } from "@sapphire/decorators";
import { Events, Listener } from "@sapphire/framework";

@ApplyOptions<Listener.Options>({
event: Events.MessageReactionAdd,
enabled: true,
once: false,
name: "reaction",
})
export class UserEvent extends Listener {
public async run() {
const { logger } = this.container;
logger.info("Reaction added");
}
}
// src/listeners/reaction.ts

import { ApplyOptions } from "@sapphire/decorators";
import { Events, Listener } from "@sapphire/framework";

@ApplyOptions<Listener.Options>({
event: Events.MessageReactionAdd,
enabled: true,
once: false,
name: "reaction",
})
export class UserEvent extends Listener {
public async run() {
const { logger } = this.container;
logger.info("Reaction added");
}
}
16 replies
TTCTheo's Typesafe Cult
Created by nexxel on 2/16/2023 in #questions
very huge typescript question
playground link: https://www.typescriptlang.org/play?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9RlzUDY+i4cuVG2LUYy1neKcK+utQHTVWc2mVeW56buBkpJIcioMg0CWXBL7njRGpfJhyBvAAaii0m5EMbG-v+v2UP9gPA2ZUOw-DSWSaD6nqkVWVJcjiqcZkGNA0eOLmS+lkACKOdDmJw9qRNjv2CkIviONsyiflDCFSUKeWhM5eOpNDCdpW8Kqy4nsuTMs7jaiKLLRjRDQS5DqkDOoMzZis+A7MiB0p2tT2-RK0O7pBrrbwxnS4j86bKI+KEN3soImDqCVWtUDrbtm+o3AG0bJuhxbA1W7wL59fLva2289uO5iztGq7qsC+rXtLN+X0cT9XGQeAACygPml8ACqmoisuYPEziXl-pQ4jtYnOU1-2Ivd7pHbF8qf5l5X0DV6AdfmWY7dpHjMuk-3cUE43nNYiTalL-s5P6cPZij1XXK1-X85DpZcSz5L3NAuWiFdxePc4oorcz35neLw-vfUQKj8-DfKdnjXpee+NFf5XgfLQMq9BijKgAeAc+ShNbkCDqQYCgML762VqgC+Md5xPnjsuRO+9kAV0BnAr4aDoAX2uksH2fsHyBxiOnLgzCEG4LljwBWQ44EawYbHBc4pHRSB4V6U6DsZ4+DgZndWoiBodxfDNTIeoFCKK3h9L0iw6H+1kXHF8+cbpLULtgbWpBBypCGmJGCPAACMXwPzEHsItEAp0AB6QYwgmNANAICTFgLmIPtAW2XweBKFJmSdcAAGUADsLr2DIMgSgAByUg6BaB8FoKWUATBICgAiY48QD1rERKiWARBoRnGuPcc48AAALTQmhdTZDJKIHgQA
36 replies
TTCTheo's Typesafe Cult
Created by nexxel on 2/5/2023 in #questions
Need help with typescript stuff
I am trying to implement the Maybe monad in typescript. It's like the Option type in Rust. Here's what I have so far:
const None = Symbol("None");

export class Maybe<T> {
constructor(private value: T | typeof None) {}

static some<T>(value: T): Maybe<T> {
if (value === null || value === undefined) return Maybe.none<T>();

return new Maybe<T>(value);
}

static none<T>(): Maybe<T> {
return new Maybe<T>(None);
}

static from<T>(value: T): Maybe<T> {
if (value === null || value === undefined) return Maybe.none<T>();

return Maybe.some(value);
}

public match<U>({ some, none }: { some: (value: T) => U; none: () => U }): U {
if (this.value === None) return none();

return some(this.value);
}

public map<U>(fn: (value: T) => U): Maybe<U> {
if (this.value === None) return Maybe.none<U>();

return Maybe.some(fn(this.value));
}

public flatMap<U>(fn: (value: T) => Maybe<U>): Maybe<U> {
if (this.value === None) return Maybe.none<U>();

return fn(this.value);
}

public getOrElse<U>(value: U): T | U {
if (this.value === None) return value;

return this.value;
}
}
const None = Symbol("None");

export class Maybe<T> {
constructor(private value: T | typeof None) {}

static some<T>(value: T): Maybe<T> {
if (value === null || value === undefined) return Maybe.none<T>();

return new Maybe<T>(value);
}

static none<T>(): Maybe<T> {
return new Maybe<T>(None);
}

static from<T>(value: T): Maybe<T> {
if (value === null || value === undefined) return Maybe.none<T>();

return Maybe.some(value);
}

public match<U>({ some, none }: { some: (value: T) => U; none: () => U }): U {
if (this.value === None) return none();

return some(this.value);
}

public map<U>(fn: (value: T) => U): Maybe<U> {
if (this.value === None) return Maybe.none<U>();

return Maybe.some(fn(this.value));
}

public flatMap<U>(fn: (value: T) => Maybe<U>): Maybe<U> {
if (this.value === None) return Maybe.none<U>();

return fn(this.value);
}

public getOrElse<U>(value: U): T | U {
if (this.value === None) return value;

return this.value;
}
}
Here the from method is used to take in a value and convert it to a Maybe<value>. For example:
const a = Maybe.from(9);
// ^? const a: Maybe<number>

const b = Maybe.from("hi");
// ^? const b: Maybe<string>
const a = Maybe.from(9);
// ^? const a: Maybe<number>

const b = Maybe.from("hi");
// ^? const b: Maybe<string>
But there's a problem, when I pass a value that could either be some type (like number, string, etc) or null or undefined, it returns Maybe<value | undefined>. The Maybe monad handles this by using none so there's no need to have Maybe<value | undefined>, it just needs to be Maybe<value> . For example:
const z = Maybe.from([1, 2, 3].pop()); // z is Maybe<number | undefined> but I want Maybe<number>
const z = Maybe.from([1, 2, 3].pop()); // z is Maybe<number | undefined> but I want Maybe<number>
How do I modify my code in order to implement this behaviour? Playground link: https://www.typescriptlang.org/play?#code/MYewdgzgLgBAcuApjAvDAygTwLYCMQA2AFAEQJiIkCUA3AFB2IAeADiAE6zAECGEEMALI9MuRAB4AKgD4YAbzowYoSFHYBXYFA5EW7AJYA3HlGTGC6xAC4YkmAB8YUTC0QgAZvCRV5AXwZK0Cb6wDAQINgSMkTmljaSVDbColGyCkpK+p4xPBbIKAUwYOoEBA6OsfmF6mAAJoju+hS1PuyIUOrsYEIiYgB0YEhS0kS0ARltHV1FiADuPSnDOXljSv6KYVDBoYMUS4kLYsPyG0qTnd0U88lH0eSIqzDrgVtQITDu7BFLlfEHN6kThkYFkYMtLKhCsVSuUYJVIWgavVGs1Wu0LodEAMhtExqcYOdpgC+uFIuCHvQ1uMWOpcAR3tgTMAABbiACqIzkYQiiAANEUkE8bFzSdYwb9bD4ULI2TQBRQbKNUDKngc2UCMqCiFBmfoIH14QU0Pc0VNLkhRvR8YTuqLtbr9ZVHs8YDS6QyeCx2SN3GBFRKEsqYGz-r0JByNZlsjq9QbchCjV4KKaMcTduGRnjgTbMSSeURffbY07ndTafTQu5eFBhF6OQW-eL42LA9LMd7Q4sI+lNdGHXG8gikw8CeiiWHsXt61mJmPuoWY47m6WNm6KzAAObtADy7AAogQIBnyTYQ-EHMHIyC+8Xm0OTaOzXDm1bs3OnP3KpSnnR1ipoDATCoLmnwREQADaACM-IAEz8gAzAAun0bAsKMYwAPQYcCAB6AD8QA
22 replies
TTCTheo's Typesafe Cult
Created by nexxel on 1/18/2023 in #questions
return type not getting inferred correctly. what am i doing wrong here?
36 replies
TTCTheo's Typesafe Cult
Created by nexxel on 1/16/2023 in #questions
a question for all the vue devs
how do you define props? do you use the special typescript syntax:
const props = withDefaults(defineProps<{ active: boolean }>(), {
active: false,
});
const props = withDefaults(defineProps<{ active: boolean }>(), {
active: false,
});
or the other way:
defineProps({
active: {
type: boolean,
default: false
},
})
defineProps({
active: {
type: boolean,
default: false
},
})
10 replies
TTCTheo's Typesafe Cult
Created by nexxel on 12/22/2022 in #questions
Need help in OOP
class Shape {
radius: number;
length: number;
breadth: number;
base: number;
height: number;

constructor(radius: number) {
this.radius = radius;
this.length = 0;
this.breadth = 0;
this.base = 0;
this.height = 0;
}
}

class Circle extends Shape {
constructor(radius: number) {
super(radius);
}

getArea(): number {
return Math.PI * this.radius * this.radius;
}
}

class Rectangle extends Shape {
constructor(length: number, breadth: number) {
super(0);
this.length = length;
this.breadth = breadth;
}

getArea(): number {
return this.length * this.breadth;
}
}

class Triangle extends Shape {
constructor(base: number, height: number) {
super(0);
this.base = base;
this.height = height;
}

getArea(): number {
return (this.base * this.height) / 2;
}
}

const circle = new Circle(10);
const radius = new Rectangle(3, 4);
const triangle = new Triangle(5, 6);

console.log(circle.getArea());
console.log(radius.getArea());
console.log(triangle.getArea());
class Shape {
radius: number;
length: number;
breadth: number;
base: number;
height: number;

constructor(radius: number) {
this.radius = radius;
this.length = 0;
this.breadth = 0;
this.base = 0;
this.height = 0;
}
}

class Circle extends Shape {
constructor(radius: number) {
super(radius);
}

getArea(): number {
return Math.PI * this.radius * this.radius;
}
}

class Rectangle extends Shape {
constructor(length: number, breadth: number) {
super(0);
this.length = length;
this.breadth = breadth;
}

getArea(): number {
return this.length * this.breadth;
}
}

class Triangle extends Shape {
constructor(base: number, height: number) {
super(0);
this.base = base;
this.height = height;
}

getArea(): number {
return (this.base * this.height) / 2;
}
}

const circle = new Circle(10);
const radius = new Rectangle(3, 4);
const triangle = new Triangle(5, 6);

console.log(circle.getArea());
console.log(radius.getArea());
console.log(triangle.getArea());
is there a better way to do this using OOP? this feels a bit inconsistent to me but im inexperienced in OOP and don't know if there's a better way to do this. would love some help!
73 replies
TTCTheo's Typesafe Cult
Created by nexxel on 11/21/2022 in #questions
jwt vs cookies in next-auth
we recommend using sessions in t3-app but i don't know why. theo says to use sessions but what are the exact reasons one would pick one over the other while using next-auth?
151 replies
TTCTheo's Typesafe Cult
Created by nexxel on 11/21/2022 in #questions
need help with a complex db query
im making a hackernews clone rn. on the home page i want to display the "trending posts": posts ordered by upvotes which were posted in the last 24 hours. but if there were no posts in the last 24 hours i wanna show the previous posts as well. and also if the user scrolls down enough i still want to show posts before 24 hours as well. how would a db query for this look like?
46 replies
TTCTheo's Typesafe Cult
Created by nexxel on 11/17/2022 in #questions
solid start routeData errors
reposting here cause got no help in solid server yet
9 replies
TTCTheo's Typesafe Cult
Created by nexxel on 11/1/2022 in #questions
how to reduce layout shift in astro
im currently in the process of rewriting my old personal site/blog in astro and i have almost finished it. but idk why the layout shift is so huge, please help deployed version: https://nexxel-dev-v2-6s310ftwp-nexxeln.vercel.app/
124 replies
TTCTheo's Typesafe Cult
Created by nexxel on 10/29/2022 in #questions
can this be further simplified
i have run into an issue in an astro template and am gonna make a pr with the fix. but the current solution feels hacky
const { href, class: className, ...props } = Astro.props;
let pathnameWithoutSlash = Astro.url.pathname.replace(/\/$/, "");

if (href === "/" && pathnameWithoutSlash === "") {
pathnameWithoutSlash = "/";
}

const isActive = href === pathnameWithoutSlash;
const { href, class: className, ...props } = Astro.props;
let pathnameWithoutSlash = Astro.url.pathname.replace(/\/$/, "");

if (href === "/" && pathnameWithoutSlash === "") {
pathnameWithoutSlash = "/";
}

const isActive = href === pathnameWithoutSlash;
can this be simplified somehow? should i just make a pr and let the maintainers review it?
111 replies
TTCTheo's Typesafe Cult
Created by nexxel on 10/28/2022 in #questions
what problem do RSCs actually solve?
title
215 replies
TTCTheo's Typesafe Cult
Created by nexxel on 10/26/2022 in #questions
Should I use next 13 or t3 stack for my current project (long term project)
if i do use t3, how difficult would it be to update to next 13 when it does become stable. also worried about how to use tRPC. i also def need the nested routing
11 replies
TTCTheo's Typesafe Cult
Created by nexxel on 10/23/2022 in #questions
best way to create reusable components with tailwind and react
i am exploring different ways to create reusable components using tailwind and react and found this https://github.com/enochndika/kimia-UI/blob/main/src/packages/button/button.tsx. is this the best way to do this?
32 replies
TTCTheo's Typesafe Cult
Created by nexxel on 10/13/2022 in #questions
zod to check if string is only whitespaces
how do i use zod to check if a string is only whitespaces?
18 replies
TTCTheo's Typesafe Cult
Created by nexxel on 9/29/2022 in #questions
medium, hashnode alternatives?
are there any alternatives to medium and hashnode? i was thinking of building something like it where you can host the blogging platform on a custom domain and was curious if there any other platforms that let you do this. i know i can build a better platform that medium/hashnode but i'd also like to see the alternatives and if they are better or worse.
1 replies