Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[type]: conditional type inference unexpected #524

Open
kelvinschen opened this issue Dec 14, 2023 · 1 comment
Open

[type]: conditional type inference unexpected #524

kelvinschen opened this issue Dec 14, 2023 · 1 comment

Comments

@kelvinschen
Copy link

import { typeOf, valuesOf, ReflectionClass, validate, is } from "@deepkit/type";

type Foo<T> = T extends [...infer P extends string[], infer L] ? L : never

type Bar = Foo<[string, string, number]> // Bar is number

console.log('valRes', is<Bar>('hello'))  // true (expect to be false)
console.log('valRes', is<Bar>(1)) // false (expect to be true)
console.log('valRes', is<number>(1)) // true
console.log('type', typeOf<Bar>()) // kind: 5 (expect to be 6)
  "dependencies": {
    "@deepkit/core": "^1.0.1-alpha.108",
    "@deepkit/type": "^1.0.1-alpha.108"
  },
  "devDependencies": {
    "@deepkit/type-compiler": "^1.0.1-alpha.108",
    "@types/node": "20.8.6",
    "ts-node": "10.9.1",
    "typescript": "^5.1"
  }

codesandbox

it seems the inference of Bar result in 'string' rather than 'number'

@marcj
Copy link
Member

marcj commented Dec 14, 2023

Infer operations with constraints are not implemented yet.

case SyntaxKind.InferType: {

We need a new bytecode OP inferConstrained or something like that to have it backward compatible, and then consume TypeParameterDeclaration.constraint in the AST node (narrowed.typeParameter.constraint)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants