Swifter
Swifter
DDeno
Created by Swifter on 11/22/2023 in #help
Language server crashing in VSC outside of deno projects
I think since the newest extension update
4 replies
DDeno
Created by Swifter on 11/22/2023 in #help
Language server crashing in VSC outside of deno projects
this just happened when I opened a standalone .dat file, and it's BEEN happening :/
4 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
would there be any way to detect if the input is Readonly and make a mutable type out of it to infer it that way?
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
I'll give you an example of what I mean.
export function preferTuple<T extends [] | number[]>(values: T) {
return values as T
}

preferTuple([1,2]) // [number, number]
export function preferTuple<T extends [] | number[]>(values: T) {
return values as T
}

preferTuple([1,2]) // [number, number]
the only with this is, as soon as I try to include readonly functionality everything breaks unexpectedly:
export function preferTuple<T extends [] | number[]>(values: Readonly<T>) {
return values as T
}

preferTuple([1,2]) // (1, 2)[]
preferTuple([1,2] as [number, number]) // [number, number]
preferTuple([1,2] as Readonly<[number, number]>) // number | []
export function preferTuple<T extends [] | number[]>(values: Readonly<T>) {
return values as T
}

preferTuple([1,2]) // (1, 2)[]
preferTuple([1,2] as [number, number]) // [number, number]
preferTuple([1,2] as Readonly<[number, number]>) // number | []
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
the thing is that I want it to assume a raw input such as degreesToRadians([0]) is a tuple, instead of assuming it's a number[]
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
this does not prefer a tuple, degreesToRadians([1]) gives me number[] when I want it to give me [number]
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
ok how about this, can you make the function also take in a number and return a converted number?
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
ok so, I want a function that takes in an array of numbers and converts them from degrees to radians. The only thing is that: - I want the function to prefer a tuple, so if I input [0,0,0], I should get out [number, number, number] - I want the function to allow for readonly inputs, since the returned array will be a new array from map
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
the problem is that DeepMutable<Geometry> is not compatible with the Geometry array
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
ok more problems, I get a massive error here:
Argument of type 'this | DeepMutable<this>' is not assignable to parameter of type 'Geometry'.
Type 'DeepMutable<this>' is not assignable to type 'Geometry'.
Types of property 'push' are incompatible.
Type 'this["push"] extends (infer R)[] ? DeepMutable<R>[] : this["push"] extends readonly (infer R)[] ? DeepMutable<R>[] : this["push"] extends Function ? this["push"] : this["push"] extends object ? DeepMutable<...> : this["push"]' is not assignable to type '(clone?: boolean) => void'.
Type 'DeepMutable<unknown>[] | (this["push"] extends readonly (infer R)[] ? DeepMutable<R>[] : this["push"] extends Function ? this["push"] : this["push"] extends object ? DeepMutable<...> : this["push"])' is not assignable to type '(clone?: boolean) => void'.
Type 'DeepMutable<unknown>[]' is not assignable to type '(clone?: boolean) => void'.
Type 'DeepMutable<unknown>[]' provides no match for the signature '(clone?: boolean): void'.deno-ts(2345)
Argument of type 'this | DeepMutable<this>' is not assignable to parameter of type 'Geometry'.
Type 'DeepMutable<this>' is not assignable to type 'Geometry'.
Types of property 'push' are incompatible.
Type 'this["push"] extends (infer R)[] ? DeepMutable<R>[] : this["push"] extends readonly (infer R)[] ? DeepMutable<R>[] : this["push"] extends Function ? this["push"] : this["push"] extends object ? DeepMutable<...> : this["push"]' is not assignable to type '(clone?: boolean) => void'.
Type 'DeepMutable<unknown>[] | (this["push"] extends readonly (infer R)[] ? DeepMutable<R>[] : this["push"] extends Function ? this["push"] : this["push"] extends object ? DeepMutable<...> : this["push"])' is not assignable to type '(clone?: boolean) => void'.
Type 'DeepMutable<unknown>[]' is not assignable to type '(clone?: boolean) => void'.
Type 'DeepMutable<unknown>[]' provides no match for the signature '(clone?: boolean): void'.deno-ts(2345)
from the expression going into geometry.push in this function:
push(clone = true): void {
getActiveDiff().geometry.push(clone ? copy(this) : this)
}
push(clone = true): void {
getActiveDiff().geometry.push(clone ? copy(this) : this)
}
getActiveDiff().geometry is Geometry[] and this outer push function is in the Geometry class. here's what the copy function looks like:
export function copy<T>(obj: T): DeepMutable<T>
export function copy<T>(obj: T): T {
if (obj === null || obj === undefined || typeof obj !== 'object') return obj

const newObj = Array.isArray(obj) ? new Array(obj.length) : Object.create(obj)

const entries = Object.entries(obj) as [keyof T, any]
entries.forEach(([k, v]) => {
// This causes a big speed boost, reaching 50%
// the JIT can just skip primitives with this
// keep in mind that's practically 6ms -> 3ms, but still
if (typeof v !== "object") {
newObj[k] = v;
return
}

const newValue = copy(v);
newObj[k] = newValue
})

return newObj
}
export function copy<T>(obj: T): DeepMutable<T>
export function copy<T>(obj: T): T {
if (obj === null || obj === undefined || typeof obj !== 'object') return obj

const newObj = Array.isArray(obj) ? new Array(obj.length) : Object.create(obj)

const entries = Object.entries(obj) as [keyof T, any]
entries.forEach(([k, v]) => {
// This causes a big speed boost, reaching 50%
// the JIT can just skip primitives with this
// keep in mind that's practically 6ms -> 3ms, but still
if (typeof v !== "object") {
newObj[k] = v;
return
}

const newValue = copy(v);
newObj[k] = newValue
})

return newObj
}
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
I get a warning from any
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
No description
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
const a = rm.geometry() // rm.EnvironmentInternals.Geometry
a.push() // works
const b = a as rm.DeepReadonly<typeof a> // rm.DeepReadonly<rm.EnvironmentInternals.Geometry>
b.push() // error
const a = rm.geometry() // rm.EnvironmentInternals.Geometry
a.push() // works
const b = a as rm.DeepReadonly<typeof a> // rm.DeepReadonly<rm.EnvironmentInternals.Geometry>
b.push() // error
rm.geometry() is not an array, sorry. hopefully this is more clear
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
const a = rm.geometry()
a.push() // works
const b = a as rm.DeepReadonly<typeof rm.geometry>
b.push() // error
const a = rm.geometry()
a.push() // works
const b = a as rm.DeepReadonly<typeof rm.geometry>
b.push() // error
this produces an error:
Property 'push' does not exist on type 'DeepReadonly<(...params: [fields: ExcludedEnvironmentFields<Geometry, EnvironmentReplacements>] | [type?: GeoType | undefined, material?: GeometryMaterial | undefined]) => Geometry>'.deno-ts(2339)
Property 'push' does not exist on type 'DeepReadonly<(...params: [fields: ExcludedEnvironmentFields<Geometry, EnvironmentReplacements>] | [type?: GeoType | undefined, material?: GeometryMaterial | undefined]) => Geometry>'.deno-ts(2339)
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
this causes functions to have the DeepReadonly property on them which causes them to not be callable
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
could you make the same thing that ADDS readonly to everything?
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
DeepMutable produces the following warning:
This provides no type safety because it represents all functions and classes
Define the function shape explicitlydeno-lint(ban-types)
This provides no type safety because it represents all functions and classes
Define the function shape explicitlydeno-lint(ban-types)
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
a type that recursively removes readonly from every property
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
would you be able to make one?
59 replies
DDeno
Created by Swifter on 11/5/2023 in #help
Overload not typing object literals
can this be done recursively?
59 replies